I'm new to Linux and I'd like to know how to delete directory under any Linux distributions?
You need to use the command called rmdir. It remove empty directories.
rmdir command syntax
mdir [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
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop














{ 14 comments… read them below or add one }
You can also use rm -rf
It,s quite helpful here,but you should be more precise.
hi
This is very useful for me
thanks
lakshmi
Thanks a lot. Thins really helped me.
Warning!
rm -rf /home/data/2000
removes all directories AND files recursively. Option -f means force i.e. to do it without prompting.
rm [options] files | directories
The rm (remove) command can delete files:
$ rm file1 file2 file3
or recursively delete directories:
$ rm -r dir1 dir2 dir3
Some Useful Options:
-f “Forces the deletion ignoring any errors or warnings.
-i “Asks before deleting each file”
-r recursively removes a dir(s) and it’s content(s). Use with extreme caution, especially if combining it with the -f option!
You can also use the rmdir command:
The rmdir (remove directory) command deletes one or more empty directories you name.
To delete an entire directory path (Use with extreme caution!) use the -p option along with the directory path (not just the directory name):
rmdir -p dir1/dir2/dir3
The above example would delete not just dir3, but dir1 & dir2 as well!
This will delete dir1,dir2 & dir3!
nice.it,s really worked.
Thanks & hats off to ur knowledge buddy
I weep for the future of Linux users if this considered praise-worthy.
What a wanker! You instruct people to delete the entire file path without warning them? Nice try sir. I wonder how many systems you helped break.
I rm -rf all the time O.o
Sure, I know people who have lost work to it, but it’s so inefficient to go through potentially a lot of prompts…
how to delete folder named \ ?
Generally speaking (depending on what shell you’re in – BSH, CSH & BASH should be fine), a “\” is an escape character, which means it transforms special characters (“\” included) into string literals. So running “rm -rf ./\\” would recursively delete a directory in the current directory by the name of “\”. Hope this helped.
I wanted to copy all files from one folder to another but leaving all folders that started with S, so i used command:
cp -R [!S]* /NewFolder/
and it seems it is doing what i wanted. i’ll update here (InshahAllah) when finished copying ..