Linux Delete Directory With rmdir Command

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

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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 17 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
17 comments… add one
  • Zootropo Sep 6, 2007 @ 7:20

    You can also use rm -rf

  • Chandrabhanu Mahapatra Oct 16, 2007 @ 8:15

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

  • lakshmikanthan May 30, 2008 @ 5:40

    This is very useful for me

  • Kamal Jun 4, 2008 @ 8:41

    Thanks a lot. Thins really helped me.

  • Scott Jan 6, 2009 @ 15:38

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

  • DNA Feb 11, 2010 @ 8:21

    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!

  • kasun Jan 21, 2011 @ 22:31,s really worked.

  • Yogendra Feb 22, 2011 @ 4:54

    Thanks & hats off to ur knowledge buddy

    • velocirapt0r Nov 25, 2011 @ 15:25

      I weep for the future of Linux users if this considered praise-worthy.

  • Hans Apr 9, 2011 @ 6:10

    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.

    • velocirapt0r Nov 25, 2011 @ 15:24

      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…

    • Mathew waller Dec 10, 2013 @ 12:43

      Think common sense comes into play if your not sure how a command works do not use it until you are sure…i wouldn’t fly a plane on instructions given to me by someone i don’t know….would you?

  • riesal Sep 21, 2011 @ 8:41

    how to delete folder named \ ?

    • velocirapt0r Nov 25, 2011 @ 15:29

      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.

  • Iqbal Sajid Mar 5, 2012 @ 9:09

    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 ..

  • shashank Aug 4, 2013 @ 14:47

    plz tell me …if we make a directory/file in the root …than how we delete it when we are login from a local user …..

  • Gham Jun 10, 2015 @ 12:51

    find /path/to/folder -type d -print -delete

    will print and delete only empty directories AND directories containing empty directories within /path/to/folder. Omit -print if you don’t need the list

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum