Delete an Empty Directory


rmdir

Removing files isn't hard at all, but what about directories?

$ pwd /home/scott/libby/by_pool $ ls pool_02.jpg  lieberman_pool  lieberman_pool_bak $ ls lieberman_pool_bak pool_01.jpg      pool_03.jpg pool_01.jpg_bak  pool_03.jpg_bak $ rm lieberman_pool_bak rm: cannot remove 'lieberman_pool_bak/':  Is a directory 


After a few moments of looking around, you might find the rmdir command, which is specifically designed for deleting directories. So you try it.

$ rmdir lieberman_pool_bak rmdir: 'lieberman_pool_bak/': Directory not empty 


Dang it! That doesn't work either. The rmdir command only deletes empty directories. In this case, the lieberman_pool_bak folder only contains four items, so it wouldn't be too hard to empty it and then use rmdir. But what if you want to delete a directory that contains 10 subdirectories that each contains 10 more subdirectories and every single subdirectory contains 25 files? You're going to be deleting forever. There has to be an easier way! For that, see the next section.



Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net