Blog

03/06/2019

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:

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.

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.

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

20/08/2019

Start your Bitcoin Exchange with our Software

Start your Bitcoin Exchange with our Software Setup your white label bitcoin exchange right away. Or create your own cryptocurrency using...
14/08/2019

How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...
14/08/2019

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....