UNIX Delete / Remove Directory Command

Posted on in Categories , , , , , last updated April 4, 2009

How do I delete / remove a directory under UNIX operating systems?

You need to use rmdir command to remove a directory. It will remove the directory entry specified by each dirname operand, which must refer to an empty directory.

For example, to remove a directory called “cppcode”, enter:
rmdir cppcode

Note:
A directory must be empty before it can be removed. Use rm command to remove all files from a directory:
cd cppcode
rm *.cpp
cd ..
rmdir cppcode

You can also recursively remove directories and subdirectories. The directory will be emptied of files and removed using rm command:
rm -r oldletters

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

20 comment

Leave a Comment