Normally when you want to delete many subdirectories in a large directory on Linux, you will have to use the command rm many times. However there is a faster way to do this. For computer users, there are many ways to delete files and folders on their computer such as using Ccleaner or creating .bat files to delete files and folders. On Linux, to delete a directory or subdirectories contained in it, we can use the Command Prompt command, also known as the CMD command.
Delete multiple subdirectories on Linux with CMD . command
For example, we have a folder named htg contains 5 subfolders. To delete 3 of them, we would normally use the command rm 3 times.
This process can be shortened by combining 3 rm statements.
To do this, type the following command and press Enter (rename the folders to the ones you want to delete on your computer).
rm -r ~/Documents/htg/{done,ideas,notes}
Each word in brackets is an extension, followed by the preceding part (~/Documents/htg/).
The above command can be divided into ~/Documents/htg/done, ~/Documents/htg/ideasand ~/Documents/htg/notesare the paths to the directory to be deleted.
After typing the command, all 3 of these subdirectories have been deleted (illustrated below).
Part -r added to the rm statement when you want to delete a directory, not just a file. If the above command does not have the –r, The system will give an error that cannot delete the folder.
If all 3 subfolders you want to delete are empty, you can use command rmdir as follows:
rmdir ~/Documents/htg/{done,ideas,notes}
If not all the subfolders you want to delete are empty, the system will only delete the wide folders and give an error that can’t be deleted for non-empty folders.
Above, Emergenceingames.com has just instructed how to delete multiple subdirectories using just one command on Linux. This saves you time instead of having to use the delete statement multiple times with each directory.
https://thuthuat.Emergenceingames.com/xoa-nhieu-thu-muc-con-tren-linux-bang-lenh-cmd-12464n.aspx
Via: howtogeek
Related keywords:
delete folder on linux using cmd
delete folder on linux with cmd, delete folder in bulk on linux,
Source link: Delete multiple subdirectories on Linux with CMD . command
– Emergenceingames.com