Delete a Directory in Ubuntu 20.04 - Best methods


Ubuntu, which is based on Debian's design was designed for personal computers (PC), but it can also be deployed on servers.

Every operating system has different types of directories that store multiple files. Storage space is a common problem nowadays in most systems, so to free up space, or to remove duplicate copies of the same directories we need to delete the directories.

A directory is a categorization structure in the file systems that contain referrals to other computer files and maybe other directories. A directory service's primary task is to control the interactions between consumers and their IT resources within an organization or manage the same type of data in one place.

Here at Ibmi Media, we shall look into the different ways to delete directories to free-up space in Ubuntu 20.04 Linux system.


Different ways of deleting a Directory in Ubuntu:

  • Delete Directory using GUI.
  • Delete Directory using the rm command.
  • Delete Directory using the rmdir command.


1. Delete Directory using GUI

If you are a beginner and don't know how to use the Linux terminal, then you can also delete the directory using the GUI method.

  • To delete the directory, left click on the directory and click on the "move to trash" option.
  • In order to delete the directory from the Documents folder, we will simply move the cursor on it and then left click on it and then click on the option "move to trash" from the drop-down list.
  • After selecting this option you should be able to see that the directory is no longer available.


2. Delete Directory using rm command

The rm command is abbreviated as "remove". This command is used to delete things from file systems like Linux like files, symbolized links, directories, and so on. This operation usually works quietly, and you should take caution while using it because after you delete files, you won't be able to recover the data of those files or directories. It does not delete directory by default unless used with some option.

i. Delete Empty Directory

To delete an empty directory using rm, run the below command:

$ rm -d directory_name

For example if you need to delete the directory name "docs1", you can simply run the below command:

$ rm -d docs1

ii. Delete Non-Empty Directory

Below mentioned command is the syntax to delete all files and directories that aren't empty using rm:

$ rm -r directory_name

-r: recursive option

For example, Run the command mentioned below to delete the non-empty "docs1" directory.

$ rm -r docs1 

Below rm is used with the -r and -f arguments to remove non-empty directory and all files without being prompted:

$ rm -rf directory_name


iii. Delete Multiple Directories

Below mentioned is the syntax to delete multiple directories using the rm command:

$ rm -r directory_name1 directory_name2 …..


3. Delete Directory Using the rmdir command

In Linux, the rmdir command is used to delete empty directories or directories from the system. Only if all of the directories specified in the command-line interface are empty, does the rmdir command erase them. If the supplied directory contains any directories or files, the rmdir command will not be able to delete them.

Below mentioned command is the syntax to remove an empty directory using rmdir:

$ rmdir directory_name


[Need help in fixing Linux system issues ? We can help you. ]


Conclusion

This article covers the different ways to delete the directory in Ubuntu Linux system. In fact, to solve the problem of storage space, we need to delete the directories which are no longer in our use. Deleting a directory (also called folder) on Linux is a common task that every user will have to perform at some time or another. This can be done via any desktop environment that you have installed, or from command line with the rm command.


For Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on LinuxAPT.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com