An Interest In:
Web News this Week
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
July 15, 2022 06:18 pm GMT
Original Link: https://dev.to/smpnjn/how-to-remove-empty-and-non-empty-directories-in-linux-2pi2
How to Remove Empty and Non Empty Directories in Linux
Removing a directory in Linux is harder than you think, and it's not uncommon to get errors that looks like this:
folder: Directory not emptyfolder: is a directory
The confusion comes because rmdir
cannot be used to delete a directory with files or folders inside of it.
Remove a non-empty directory on Linux
To remove a directory on linux, which is not empty, pass the -r
flag to rm
. -r
means recursive, so it deletes everything in a folder, including the folder itself. Replace 'folder' below with your folder's name or location.
rm -r folder
Remove multiple non-empty directories on Linux
If you want to remove multiple directories on linux, and they are not empty, simply separate the folder names with a space, and use rm -r
:
rm -r folder1 folder2 folder3
Remove an empty directory on Linux
If you want to remove a directory on linux, and your directory is empty, with no folders or files in it, then use rmdir:
rmdir folder
Original Link: https://dev.to/smpnjn/how-to-remove-empty-and-non-empty-directories-in-linux-2pi2
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To