HowTo: Deleting Directories in Linux

How do I delete a directory or directories in Linux using the Terminal application?

You can delete the directory using any one of the following command:

ADVERTISEMENTS

rmdir command : It removes the directory entry specified by each directory argument, provided it is empty.

rm command : It removes the file. But, can be used to remove directory too even if directory is not empty.

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Requirementsrmdir/rm
Time1m

Syntax: Remove an empty directory with the rmdir command

The basic syntax is:

rmdir dirNameHere

To remove an empty directory called foo in the current directory, enter:

rmdir foo

To remove an empty directory called foo in the current directory, enter:

rmdir foo

To remove an empty directory called foo/bar, enter:

rmdir -p foo/bar

Syntax: Remove directory and all its files including sub-directories with the rm command

The basic syntax is:

rm -rf dirNameHere

Warning: There is no undo in the command line/shell. So be careful with the following command. You may loss data permanently.

To remove movies-mp3 directory, enter:

rm -rf movies-mp3

More more information see rmdir(1) and rm(1) command man pages.

🐧 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
2 comments… add one
  • aref ghobadi Aug 17, 2015 @ 15:41

    Hi
    thanks a lot, very nice article

  • zergh Mar 15, 2016 @ 6:40

    what the command for delete files using terminal ubuntu…full command

Leave a Reply

Your email address will not be published.

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