There are not many operating systems out there, but the one available are worth being recognized. Currently, there are about just five types of operating systems that are being used in the modern digital market to act as fundamentals for your smartphones or computers. Linux is used in around 36.7% of websites, while 54.1% of developers prefer it. Since the commencement of Linux, about 1513 companies have contributed to its development. But sometimes carrying out basic operations or getting stuck in some is a very tedious task to get out from on your own on Linux. And this article is the right place to get your errors corrected and educate yourself.
Directories are locations that store the data of every user that is created. Every time users make a profile, new data is created. If you are used to working in Windows, the layout of the Linux file system may appear mainly foreign. The letters C:\ drive and drive letter are out-dated and are replaced by folders that look like a / and mysterious-sounding directories, mostly having three-letter names. The configuration of data files on Linux as well as other UNIX-like operating systems is specified by the Filesystem Hierarchy Standard (FHS). Linux file systems, however still include specific directories that are not bound by the specification yet.
Directories require multiple functions that need to be executed for them to display their proper use. Besides, Linux distinguishes between upper- and lower-case letters, e.g. The file called test varies from the file named TEst, and so on. However, Linux makes no distinction between a directory and a folder. In UNIX, if it’s not a file, then it’s a process as simple as that. Without deviating from the motto of our article, let’s see how to remove a directory in Linux.
Removing directory in Linux
Linux has only two types of the directory. It can either be null or have some content in it. If you’re using a computer file browser like Gnome’s Files or KDE’s Dolphin, you can uninstall files and folders by using the graphical interface of the manager. But whether you’re running on a headless server or want to uninstall several files at once, deleting directories (folders) from the command line is your best choice.
Rmdir is the command line used for deleting the directories. This command can be used to close the guides even if they are not empty as using this command abolishes the need to verify the nullity of the directory. The rmdir base is the best-established way to remove the directory in Linux.
- Using the rm command to uninstall all files and subdirectories. For example, to delete *.doc files and all subdirectories and folders in the directory with letters, type the following command: $ rm -rf letters/.
– Here -r refers to the removal of the directory that is hierarchically rooted in each of the files argument. It is hence removing all of the subdirectories too.
– -f refers to the attempt of removal of files without confirmation as it usually asks for while removing the directories.
- If you encounter permission denied that shows that only an owner can delete the file and that you are not authorized for it. In that case, the sysadmin can delete the unwanted directories using the command. Make sure to enter the admin password to proceed.
– sudo rmdir /path/to/dir/
– sudo rm -rf dir2
- Command used to delete all the unwanted directories can be used when you want to delete the directories with the same name to clean any residual files of the current session.
– find. -type d -iname ‘session’ -delete
– find. -type d -iname ‘session’ -empty -delete
To delete all directories that are in the form of.DS_store in /var/www/html.
– sudo find /var/www/html/ -type d -name .DS_Store -exec rm {} \;
– sudo find /var/www/html/ -type d -name .DS_Store -exec rm {} +
Summary
Directories can acquire unwanted space if not deleted and kept note of and can cause an unwanted error while executing a directory of the same name as it might confuse the system which one do you want to utilize. Also, it should be noted that removing directories is a one-way thing as once they are removed, they cannot be recovered again. Following the above commands and keeping the notes of points stated in this article, there is a hard chance you will face major issues while removing a directory in Linux.