
Follow ZDNET: Add us as a favorite source On Google.
Linux makes it quite simple to interact with your PC and your apps. Anything you can do on proprietary operating systems like Windows and macOS, you can do with open-source OSes, ranging from simple to complex.
However, often the simplest tasks can be a little confusing, especially when you are new to something. For example, how do you delete a directory (aka “folder”) on Linux?
Also: The First 8 Linux Commands Every New User Should Learn
Sounds simple, right? it is! Just like on macOS or Windows, deleting a directory on Linux can be done by anyone regardless of skill level.
I’ll show you two easy ways to do this, and I’ll also include a bonus method that offers a more secure way to delete a directory.
Method 1: From File Manager
what you’ll need: All you need for this is a desktop Linux distribution and a directory to delete. I will demonstrate this on Pop!_OS with the COSMIC desktop, but the process will be the same regardless of Linux distro or desktop environment.
I recommend creating a test directory to avoid accidentally deleting the wrong directory. To create a new directory within the file manager, right-click on any empty space in the directory and click New Folder. If you are using KDE Plasma, you will need to right-click on an empty space in the file manager and then click New > Create Folder.
Let’s delete the test directory you just created. Open your file manager and locate that directory.
show more
Right-click the directory to be deleted and then click Move to Trash. If you don’t see an entry for Move to Trash, you should see a Delete entry.
show more
Pop!_OS Deleting a file from within the COSMIC file manager.
Screenshot by Jack Wallen/ZDNET
This process works for both empty directories and directories containing files/folders.
Also: My Top 5 Password Managers for Linux – And My Favorites Work on Windows and macOS Too
You can then empty your Trash so that the file is permanently deleted.
Method 2: From command line
Deleting a directory from the command line is a little tricky, but not overly difficult. This is done with the rm command.
Open your Terminal app
The first step is to open your Terminal app.
change to correct directory
Next, go to the location where the directory to be deleted is located. For example, let’s say the directory to be deleted is located in /home/jack/Documents. To change to that directory, issue the command:
cd ~/documents
~/ is shorthand for your home directory.
Note: you don’t do this to pass To change the location of the directory to be deleted. If you don’t do this, you must use the full path to the directory you want to delete.
delete directory
Suppose the name of the directory to be deleted is TESTING. To delete that directory, whether it’s empty or contains files/folders, you would delete it with the command:
rm-rf test
If you just use the command rm TESTING, it will fail because you are deleting a directory. -RF options are:
- R – Recursively – Deletes all files/folders within a directory and then deletes the directory itself.
- F – forces deletion.
You do not need to use the f option. For whatever reason, I automatically use it.
You can also use the interactive mode, which will:
rm-ri test
When deleting in interactive mode, you will be asked to OK at each step.
bonus method
For some people, using one of the above methods is not enough, especially if a directory contains files containing sensitive information that needs to be deleted.
Also: 5 Obscure Linux Distros You’ve Probably Never Heard Of – But Should Definitely Try
If this is the case, you will want to use the shred command to overwrite the internal files/folders with 1s and 0s and then delete the directory with one of the above methods.
The shred command works like this:
shred -u -z -n 3 file
Where FILE is the name of the file to be deleted.
The above options are as follows:
- -u – Deallocate and delete the file after overwriting.
- -z – Add a final overwrite with zeros to obscure shredding.
- -n x – (where x is a number above 3) indicates how many iterations are used for overwriting. Default is 3.
After you’ve fragmented all the files you have, delete the directory from your file manager or with the rm command.

