How to Delete a Directory in Ubuntu 22.04 (With Examples)

Ubuntu, one of the greatest Linux distributions presently offered, is built on the Debian architecture. This Linux distribution may be installed on servers even though it was created for personal computers (PCs). There are several sorts of folders for storing numerous files on every operating system. Nowadays, most systems struggle with storage capacity, thus we need to delete directories to make room or get rid of duplicate copies of the same directories. In this post, we’ll go through the several techniques Ubuntu offers to remove folders and clear up space.

In file systems, a directory is a structure for classification that includes links to other computer files and sometimes other directories. The main function of a directory service is to handle the same kind of data in one location or to manage interactions between users and their IT resources inside an organization. The procedure for deleting a directory on an Ubuntu 22.04 system will be covered in this article.

Delete a Directory in Ubuntu 22.04

Ubuntu provides both ways to delete the directory: Graphical User Interface and Command Line interface. Below mentioned are some ways to delete a directory.

  • Delete Directory via GUI
  • Delete Directory via Terminal

Below these ways are explained in detail.

Delete Directory using GUI

You may also remove the directory using the GUI technique if you are a newbie and are not familiar with using the Linux terminal.

Right click the directory and choose “move to trash” from the menu that appears. I will place the mouse over the “Linux” directory in the Documents folder, left click on it, and then choose the option “move to trash” from the drop-down list, as shown below, to remove it.

As seen below, after choosing this option, you should be able to notice that the directory is no longer accessible.

Delete Directory via Terminal

With the “rm” command, you can remove anything from Linux file systems such as files, symbolic links, directories, and more. Since you won’t be able to retrieve the data from deleted files or directories, you should exercise care while utilizing this process, which often operates silently. Unless a specific option is supplied, it does not by default destroy any directories.

How to Delete Empty Directory

Rm can be used to remove an empty directory using the syntax listed below.

$ rm -d directory_name

The Linux directory will be removed in the below output:

Deleting Non-Empty Directory

The syntax to use when using rm to remove all files and folders that aren’t empty is listed below.

$ rm -r directory_name

-r: recursive option

The rm command is used with the -r and -f options to silently delete all files and non-empty directories:

$ rm -rf directory_name

Deleting Multiple Directories

The syntax for using the rm command to remove several directories is listed below.

$ rm -r directory_name1 directory_name2 …..

Alternate Method to Delete Directories in Ubuntu 22.04

The “rmdir” command in Linux is used to remove directories or empty directories from the computer. The rmdir command will only remove directories if all of the directories supplied in the command-line interface are empty. The rmdir command will be unable to remove any directories or files that are present in the provided directory.

The syntax for using rmdir to delete an empty directory is listed below.

$ rmdir directory_name


We must remove the folders that are no longer needed in order to remedy the storage space issue. Ubuntu offers many options for deleting the directory. In this post, we have talked about removing directories using the GUI, “rm,” and “rmdir” commands. These techniques are all covered in depth.

Print Friendly, PDF & Email