Linux delete directory with rmdir command

Q. I'm new to Linux and I'd like to know how to delete directory? I'm using Cent OS Linux.

A. You need to use command called rmdir. It remove empty directories

rmdir command syntax

rmdir [OPTION] {directory-name}

Delete / remove directory

To delete directory called foo, enter:
rmdir foo

Remove DIRECTORY and its ancestors

For example remove directory structure sales/99/march
rmdir -p sales/99/march

Recursive delete

Remove all directories and subdirectories, use rm command with -r option:
rm -rf /home/data/2000

Please note that rmdir command works with all Linux and Unix like operating systems. For more information read rm and rmdir command man pages:
man rm
man rmdir

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 5 comments… read them below or add one }

1 Zootropo 09.06.07 at 7:20 am

You can also use rm -rf

2 Chandrabhanu Mahapatra 10.16.07 at 8:15 am

It,s quite helpful here,but you should be more precise.

3 lakshmikanthan 05.30.08 at 5:40 am

hi
This is very useful for me
thanks
lakshmi

4 Kamal 06.04.08 at 8:41 am

Thanks a lot. Thins really helped me.

5 Scott 01.06.09 at 3:38 pm

Warning!
rm -rf /home/data/2000
removes all directories AND files recursively. Option -f means force i.e. to do it without prompting.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , ,

Previous post: Linux Create User Account

Next post: Ubuntu Linux stop / disable GNOME GUI ~ X.org