UNIX Delete / Remove Directory Command

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.

ADVERTISEMENTS

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

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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 VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
20 comments… add one
  • kjgkd Oct 19, 2009 @ 16:33

    Hi thanks..

  • neha Apr 6, 2010 @ 0:51

    Thank You

  • ashok kumar Jun 1, 2010 @ 15:04

    thank u.I want more basic comends in unix

  • Sumit Jain Dec 16, 2010 @ 12:23

    What are the other conditions for deleting/removing directories…….?

  • sathya Jan 28, 2011 @ 6:41

    Thanks

  • chester Jul 5, 2011 @ 5:30

    learning unix begins with deleting directories.

  • sunny Aug 3, 2011 @ 4:50

    The commands are well explained with proper example. Very helpful!!

  • Helloindia Sep 6, 2011 @ 15:36

    Thanks.

  • Buki Sep 14, 2011 @ 17:38

    Fantastic! Thank you!

  • Shoaib Jul 27, 2012 @ 12:35

    Thanks !!

  • Kiruba Oct 3, 2012 @ 6:27

    Thanks. It works.

  • karan Oct 11, 2012 @ 17:21

    if you do rm -fr cppcode, it will forcefully delete the directory(making it empty and delete).

    Thanks,
    KARAN

  • Guru Oct 14, 2012 @ 2:14

    It helped me :) thanks a tone :))))))

  • Harun R Nov 12, 2012 @ 21:11

    You could also do a:

    rm -rf

  • shahebaz Apr 2, 2013 @ 5:38

    thaks bt i want more

  • srinath Apr 19, 2013 @ 13:57

    Thanks it works

  • Abhinandan Jun 10, 2014 @ 7:10

    thanks a lot..it solved my problem in a beautiful way

  • Anand Sep 25, 2014 @ 16:51

    rm -fr also removed forcefully.

  • avinash Mar 9, 2015 @ 11:58

    Is there any way to delete directory recurisively,,without deleting content of each directory .

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.