How to remove Linux directory

Operating systems based on Linux kernel usually stores a large number of empty and nonempty directories. Some of them occupy a lot of space on the drive, and often become unnecessary. In this case, the correct way is removing them. How to perform cleaning, there are several, each of them is applicable in a certain situation. Let’s look at all the available methods in more detail, and you choose the most appropriate based on their needs.

Remove directories in Linux

In this article we’ll talk about the console utilities and additional tools, start using command input. But do not forget that often the distributions implemented a graphical shell. So to remove the directory you just need to navigate to it via file Manager, click the right mouse button on the icon and choose “Remove”. Do not forget to empty the trash. However, not all users of this variant would be applicable, so we advise you read the following guidelines.

Before consider how important to note that when you type the command you’ll most often choose to specify the name of the folder you want to delete. When you are not in her location, you should specify the full path. If possible, we recommend you to read the parent directory object and use it via the console. Executes this action in just a few minutes:

  • Open file Manager and navigate to storage folder.
  • Click on it RMB and choose “Properties”.
  • In the tab “General” find the full path and remember it.
  • Start the console via the menu or using the default hotkey Ctrl + Alt + T.
  • Use cdto go to work in the location. Then the input string takes the form cd /home/user/folder and actinoide after pressing Enter. User in this case, the user name and folder — name of the parent folder.
  • If you do not have the ability to determine the location, if you delete you will have to enter the full path yourself, so you need to know.

    Method 1: Standard command “Terminal”

    In a command shell of any Linux distribution there is a set of basic utilities and tools that allows you to perform a variety of actions with the system settings and files, including delete the directories. Such tools, there are several and each will be most useful in a certain situation.


    First of all I would like to touch on rmdir. It is designed to clean the system only on empty directories. Removes them permanently, and the advantage of this tool lies in the simplicity of its syntax and the absence of any errors. In the console you need to register rmdir folder, where folder is the folder name in the current location. The activation tool is made by pressing Enter.

    Nothing prevents to specify the full path to the directory if you can’t navigate to the required location or there is no need. Then the string becomes, for example, the following: rmdir /home/user/folder/folder1, where user is the name of the user folder is the parent directory and folder1 is the folder to delete. Please note that before home you must put the slash at the end of the road he should be absent.

    The command rm

    The preceding tool is one of the components of the utility rm. Initially it is designed to remove files, but if you give it the appropriate argument, it will erase and folder. This option is suitable for non-empty directories in the console when it is necessary to enter rm-R folder (or directory path). Note the argument to -R — he runs the recursive deletion, i.e., it concerns the contents of a folder and the folder itself. Case sensitivity when typing is necessary, because -r is another option.

    If you want to display a list of all deleted files and folders when you use rm, then you will need to slightly modify the string. Type in “Terminal” rm-Rfv folder, and then activate the command.

    After the removal is completed displays information about all the directories and individual facilities, previously located at the specified location.

    The find command

    On our site there is material examples of use of find operating systems, developed on the Linux kernel. Of course, there are only the basic and the most useful information. You can access it by clicking on the following link, and we propose now to learn how this tool works if you need to remove directories.

    Read more: Examples of using find command in Linux

  • As you know, find is used to search for objects within the system. Thanks to the use of additional options you can find directories with a specific name and immediately delete them. To do this, in the console, type find . -type d -name "folder" -exec rm-rf {}; where folder is the name of the directory. Be sure to write the double quotation marks.
  • In a separate line sometimes displays information about that file or directory does not exist, but that does not mean that he was not found. Just find work again after deleting the directory from the system.
  • find ~/ -empty-type d -delete allows you to delete all empty folders in the system. Some of them are available only to the superuser, so before you find you should add sudo.
  • The screen will display information about all the found objects and the success of the operation.
  • You can also specify only a directory where the tool will search and clean it. Then the string will look like this: find /home/user/Folder/ -empty-type d -delete.
  • This interaction with standard console tools in Linux is now complete. As you can see, there are a large number of and each is applicable in certain situations. If you have a desire to see the other popular teams, see separate our stuff at the link below.

    Method 2: wipe Utility

    If the previous tools built into the shell, then wipe utility will need to independently establish their official repository. Its advantage is that it allows you to permanently remove a directory without the possibility of its recovery using special software.

  • Open “Terminal” and type there sudo apt install wipe.
  • Enter the password to confirm the account.
  • Expect finish adding new packages to the system libraries.
  • You only have to navigate to the desired location, or write the command with the full path to the folder. It looks like this: wipe-rfi /home/user/folder or just wipe rfi folder in the preliminary implementation of the cd + the path.
  • If the work tool wipe had to face for the first time, insert in the console wipe -helpto get usage information of this utility from the developers. You can see a description of each argument and option.

    Now you are familiar with terminal commands that allow you to remove empty or non-empty directories to the OS developed on Linux. As you can see, each tool operates differently, and therefore will be optimal in different situations. Before starting tools is highly recommended to verify the specified path and folder names to avoid any mistakes or accidental deletions.


    (Visited 39 times, 1 visits today)