Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Permanently Delete Files Linux CLI & GUI

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

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

  1. Open a terminal by pressing Ctrl+Alt+T or searching for "Terminal" in your applications menu.
  2. Use the rm command to delete a single file permanently. For example, to delete file.txt in your current directory, type rm file.txt and press Enter. The file is removed immediately without going to trash.
  3. Delete a directory and its contents with the recursive flag: rm -r myfolder. This removes the folder and everything inside it. Add -f to force deletion without prompts: rm -rf myfolder. Be extremely careful: this does not ask for confirmation.
  4. Use shred to overwrite the file's data before deletion, making recovery harder. Run shred -u file.txt to overwrite the file multiple times and then remove it. Add -z for a final zero pass: shred -uz file.txt.
  5. Overwrite free space if you want to erase traces of already-deleted files. Use dd if=/dev/zero of=/tmp/wipe bs=1M status=progress to fill the disk with zeros (stop when the disk is full), then delete the temporary file with rm /tmp/wipe. This is slow but thorough.

GUI Methods

  1. Open your file manager (e.g., Files on GNOME, Dolphin on KDE).
  2. Navigate to the file or folder you want to delete.
  3. Right-click the item and select Move to Trash (or simply press the Delete key). This does not permanently delete it yet.
  4. 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.
  5. 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 -rf carelessly: A single typo (like rm -rf / home instead of rm -rf /home) can wipe your system. Always double-check the path.
  • Assuming rm sends files to trash: It does not. Once you run rm, the file is gone immediately.
  • Forgetting that shred doesn'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 -r on a symlink to a directory, it may delete the target's contents. Use rm symlink without -r.
  • Emptying trash without reviewing contents: Once emptied, there is no way to recover files from the trash.

Tips

  • Use wildcards with caution: rm *.txt deletes all .txt files in the current directory. Test with ls *.txt first to see what matches.
  • Create an alias for safe deletion: Add alias rm='rm -i' to your .bashrc to 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 trash in the terminal to send files to the trash instead of permanent deletion: gio trash file.txt.
  • Check disk space after deletion with df -h to confirm space was freed.

Troubleshooting

  • "Permission denied" errors: You don't have write permission for the file or directory. Use sudo rm file to 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 file to 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 shred or overwrite the entire disk with dd (this is destructive to the whole drive). For SSDs, consider using the blkdiscard command 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 mount and 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.