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 LinuxAPT, we shall look into the different ways to delete directories to free-up space in Ubuntu 20.04 Linux system.
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.
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 …..
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
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.