Linux Delete Folder

How do I delete folders under Linux operating systems?

You can the folder or directory, if they are empty using the following rmdir command.

Syntax

rmdir foldername
rmdir dirname
rmdir /path/to/folder
rmdir /path/to/directory

rmdir foldername
rmdir dirname
rmdir /path/to/folder
rmdir /path/to/directory

Example

In this example, delete the directory called /tmp/letters

rmdir /tmp/letters

rmdir /tmp/letters

Task: Remove DIRECTORY and Its Ancestors

The -p option can delete directory and its subdirectories:

rmdir -p dir1/dir2/dir3

rmdir -p dir1/dir2/dir3

Task: Delete All Files and Folders Including Subdirectories

Use the following syntax:

rm -rf /path/to/dir

rm -rf /path/to/dir

For example, delete /home/vivek/docs and all its subdirectories including file, enter:

rm -rf /home/vivek/docs 
ls -l /home/vivek/docs

rm -rf /home/vivek/docs
ls -l /home/vivek/docs

GUI File Manager

The Nautilus file manager (GNOME desktop) provides a simple and integrated way to manage your files and applications. Just open it from Places menu and select folder and hit delete key.

Fig.01: Gnome File Browser

Posted by: SXI ADMIN

The author is the creator of SXI LLC 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.