Removing a Directory In Linux

by on January 15, 2010 · 0 comments· last updated at December 15, 2010

How do I remove a directory in Linux using the shell prompt?

You can use the following commands:

[a] rmdir command : remove empty directories.

[b] rm command : remove files or directories.

Linux Delete a Directory Command Examples

The syntax is as follows:

 
rmdir dirName
 

Login using the ssh client or open a command-line terminal (select Applications > Accessories > Terminal under Gnome desktop), than type the following command to delete empty directory called foo:

 
rmdir foo
 

By default, the rm command does not remove directories. Use the --recursive (-r or -R) option to remove each listed directory, too, along with all of its contents including all files and subdirectories:

 
rm -r documents
 

You can also specifiy the full path:

 
rm -r /data/dir1
rm -r /home/vivek/dir2
rmdir $HOME/mp3
 


You should follow me on twitter here or grab rss feed to keep track of new changes.

Featured Articles:

{ 0 comments… add one now }

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <kbd> <blockquote> <pre> <a href="" title="">

Tagged as: , , , , , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: