- slide 1 of 9
Understanding how to discard directories and sub-directories you no longer need on your system using the Linux delete file function is essential to managing resources. You may also refer to this function as the Linux remove directory operation. First, to clarify, a directory or sub-directory is a folder and is usually represented by an icon of a manilla folder. Directories often hold files. You have two methods for removing unwanted directories; the easiest and most popular way is to use the Graphical User Interface (GUI) available in your distribution. Keep in mind that not all GUI's will appear the same. You usually right click on the directory you want or need to delete, look for a menu window to appear, and choose the logical option to remove it. That option may have various titles.
- slide 2 of 9
The Linux Delete Directory Function in a GUI
I'll use two Linux distributions (distros) to better illustrate the differences you'll encounter. In Puppy Linux, you delete a directory by right clicking on it. A menu will appear in which you'll see the name of the directory on which you clicked. Your mouse pointer should automatically land on this name. Within a second, another menu will appear in which you'll see the option "Delete Ctrl+X" and an icon of a trash can next to it. You simply point your mouse over the delete option and click once. Alternatively, you can open the parent directory holding the sub-directory and press "Ctrl+X." You'll see the mouse pointer turn to an X after which you'll then click on the directory you want to discard.
- slide 3 of 9
Once you do this, Puppy will ask if you really want to delete the directory. You have the options: Cancel, No, Yes, Quiet. If you don't want to delete the directory simply choose "Cancel" or "No." If you do want to delete it without any further questions, choose "Quiet." If you choose "Yes," you'll be asked to verify the deletion of every sub-directory and file stored in the parent directory. This can be a good thing if you truly want to confirm before deletion; it could also become annoying if you know you don't need anything in the directory. If this is the case and you don't want to be bothered with further questions, it's best to choose "Quiet." Below are screen shots of this Linux delete directory function in Puppy; simply click to enlarge them. I chose to click "Yes" to show the confirmation you would see.
- slide 5 of 9
Deleting a directory in a GUI in the Fedora distro also requires right clicking on the folder to open a menu list in which you'll see the option "Move to Trash." That's pretty self-explanatory. You can also click once to highlight the directory and press the delete key. Keep in mind that it still exists, it has just been removed to the trash which you'll want to periodically empty, also accomplished by right clicking. The screen shot below shows what this operation looks like.
- slide 6 of 9
The Linux Remove Directory Function in a Terminal
If you're a regular Microsoft Windows user, you're probably not interested in the Linux remove directory function on the command line. However, this basic operation isn't hard and the more you learn to work in text-based mode, the more control you'll have over the system.
- slide 7 of 9
You can access the interactive command prompt known as a shell by opening a terminal, called a console on some systems. In both Puppy and most versions of Fedora, you'll see this option on the desktop or you can press Ctrl+Alt+F2. New users of Linux will be less comfortable with this way because you'll be prompted to log in. The Linux delete directory operation from within a terminal can be more intimidating because you need some familiarity with the Linux file system to find your directory.
- slide 8 of 9
Basically, once you're at the directory you wish to remove, you can type rmdir Sample, where Sample is replaced by the actual name of your directory. Please note that this will only work if it's empty. If it isn't and you try this, you'll get an error message as show in the screen shot below. I attempted to use this Linux remove directory function to delete Test Dir which was not empty to show you what will happen. If the directory contains sub-directories or files, you'll need to use the rm command with at least the -r parameter which stands for recursive. If you don't want to be asked to confirm the deletion of each sub-directory and file, you might want to also pass the -f argument. Argument is another term for parameter. This last argument will force deletion without question. Be very careful with this powerful command, if you're not accurate in your typing, you could end up removing data you meant to keep. The command I entered to delete a practice directory called Test Dir containing a sub-directory and files was rm -rf Test\ Dir. The \ is an escape character needed because of the space in the name Test Dir. This wouldn't be needed if the name was TestDir. This directory was on my desktop so I had to be in my desktop directory before issuing the command to make it work. Always pay attention to where you are in the file system.