Permanently Delete Files Linux CLI & GUI
In this article
Deleting files in Linux usually sends them to a trash folder, which still takes up disk space until emptied. This guide shows how to permanently erase files and directories using both command-line tools and graphical applications, so the data is gone and unrecoverable by normal means. You'll need a Linux system with standard utilities (most distributions include them) and, for GUI methods, a desktop environment like GNOME, KDE, or Xfce.
What You'll Need
- A Linux computer with sudo or root access for system-level deletions (optional but recommended for protected files).
- Basic familiarity with opening a terminal (Ctrl+Alt+T on most distributions).
- For GUI methods, a file manager such as Nautilus (GNOME), Dolphin (KDE), or Thunar (Xfce).
Step-by-Step
Command-Line Methods
- Open a terminal by pressing Ctrl+Alt+T or searching for "Terminal" in your applications menu.
- Use the
rmcommand to delete a single file permanently. For example, to deletefile.txtin your current directory, typerm file.txtand press Enter. The file is removed immediately without going to trash. - Delete a directory and its contents with the recursive flag:
rm -r myfolder. This removes the folder and everything inside it. Add-fto force deletion without prompts:rm -rf myfolder. Be extremely careful: this does not ask for confirmation. - Use
shredto overwrite the file's data before deletion, making recovery harder. Runshred -u file.txtto overwrite the file multiple times and then remove it. Add-zfor a final zero pass:shred -uz file.txt. - Overwrite free space if you want to erase traces of already-deleted files. Use
dd if=/dev/zero of=/tmp/wipe bs=1M status=progressto fill the disk with zeros (stop when the disk is full), then delete the temporary file withrm /tmp/wipe. This is slow but thorough.
GUI Methods
- Open your file manager (e.g., Files on GNOME, Dolphin on KDE).
- Navigate to the file or folder you want to delete.
- Right-click the item and select Move to Trash (or simply press the Delete key). This does not permanently delete it yet.
- Empty the trash to permanently delete the items. In most file managers, right-click the Trash icon on the sidebar and choose Empty Trash, or open the Trash folder and click the "Empty Trash" button.
- For immediate permanent deletion without trash, hold Shift while pressing Delete (or right-click and select Delete Permanently if available). This bypasses the trash, but be careful—there is no undo.
Common Mistakes
- Using
rm -rfcarelessly: A single typo (likerm -rf / homeinstead ofrm -rf /home) can wipe your system. Always double-check the path. - Assuming
rmsends files to trash: It does not. Once you runrm, the file is gone immediately. - Forgetting that
shreddoesn't work on journaled filesystems (like ext4) as effectively as on older ones. It still helps but may not fully prevent recovery. - Not checking if a file is a symlink: Deleting a symlink removes the link, not the target, but if you use
rm -ron a symlink to a directory, it may delete the target's contents. Userm symlinkwithout-r. - Emptying trash without reviewing contents: Once emptied, there is no way to recover files from the trash.
Tips
- Use wildcards with caution:
rm *.txtdeletes all .txt files in the current directory. Test withls *.txtfirst to see what matches. - Create an alias for safe deletion: Add
alias rm='rm -i'to your.bashrcto always prompt before deleting. - For sensitive data, use full-disk encryption from the start. If your drive is encrypted, deleted data is much harder to recover.
- Use
gio trashin the terminal to send files to the trash instead of permanent deletion:gio trash file.txt. - Check disk space after deletion with
df -hto confirm space was freed.
Troubleshooting
- "Permission denied" errors: You don't have write permission for the file or directory. Use
sudo rm fileto delete with administrative privileges, but be absolutely sure of the path. - File is busy or in use: Close any applications using the file, or use
lsof fileto see which process has it open, then terminate that process. - Trash won't empty: Sometimes files in trash have permission issues. Open the trash folder, right-click the problematic file, and select "Delete Permanently" or use
sudo rm -rf ~/.local/share/Trash/files/*in the terminal. - Recovery tools still find data: If you need to ensure data is unrecoverable, use
shredor overwrite the entire disk withdd(this is destructive to the whole drive). For SSDs, consider using theblkdiscardcommand to securely erase blocks. - GUI option "Delete Permanently" is grayed out: This usually happens when the file is on a read-only filesystem or you lack write permissions. Check the mount options with
mountand remount with write access if needed.
Frequently Asked Questions
Does rm permanently delete files?
Yes, rm removes the file's directory entry immediately, and the space is marked as free. However, the actual data may remain on the disk until overwritten, so recovery tools might still find it.
Can I recover a file deleted with rm?
If you haven't written new data to the disk, you might recover it using tools like testdisk or photorec. But there is no guarantee, and the longer you wait, the lower the chances.
What is the difference between rm and shred?
rm simply removes the file reference. shred overwrites the file's content with random data before deleting it, making recovery much harder. Use shred for sensitive files.
Is there a way to permanently delete files from the GUI without Shift+Delete?
Yes, you can empty the trash after moving files there. Alternatively, some file managers have a "Delete Permanently" option in the right-click menu, but it may need to be enabled in settings.
Does emptying the trash free up disk space immediately?
Yes, emptying the trash frees the space immediately. However, if the files were on an SSD, the controller may still hold data in cache until overwritten, but from the filesystem's perspective, the space is available.
Can I permanently delete files from an external drive?
Yes, the same commands and GUI methods work on external drives. Just ensure the drive is mounted and you have write permissions. For maximum security, use shred before deleting.