Hey everyone, let’s talk about securely deleting files in Linux. It’s super important to make sure sensitive data is really gone and can’t be recovered easily. Just hitting delete isn’t always enough! Here are some ways to make sure your files are gone for good, using both the command line and GUI tools.
Command Line Methods for Secure Deletion
Method 1: Using srm
The srm
command is part of the secure-delete
package and is your best bet for truly deleting files. It overwrites the file multiple times, making recovery very, very difficult.
To get srm
on Debian/Ubuntu-based systems, use:
sudo apt install secure-delete
For older Ubuntu versions (14.04 and below) , use apt-get
instead of apt
.
On Red Hat distros, you’d do this:
yum install secure-delete
To securely delete a folder and its contents recursively:
srm -r foldername/
The -r
flag ensures that the directories and all their content are securely deleted.
Method 2: Using shred
The shred
command is another way to overwrite files with random data. It makes it really hard to recover what was there before.
To overwrite a file:
shred filename
By default, shred
overwrites the file three times, but you can choose how many times you’d like it to overwrite.
To overwrite it 10 times, for example:
shred -n 10 filename
shred
only overwrites the file’s data. It doesn’t delete it by default. To actually remove the file after overwriting, you can do this:
shred -n 10 --remove filename
Note that shred
doesn’t have a recursive option. It’s mostly for individual files.
Method 3: Using rm
The rm
command is the basic way to remove files in Linux. It just removes the directory entries for a file, which makes the file inaccessible, but the actual data may still be on the drive. It can be recovered using specialized tools. Use it for non-sensitive files.
To delete one or more files:
rm file1 file2 /home/user/file3
To delete directories and their content, use the -r
flag:
rm -r dir1 /home/user/dir2 file3
GUI Tools for Secure File Deletion
Method 1: Using Nautilus with a Secure Delete Option
Nautilus, which is the file manager in many Linux distros, has an option for a permanent delete that bypasses the trash.
- Open Nautilus and find the files or folders you want to delete.
- Select the file(s) or folder(s) and hit Shift + Delete.
- A confirmation box will pop up; click “Delete” to remove them permanently.
To add a Delete option to the right-click context menu:
- Go to “Edit” > “Preferences” in Nautilus.
- Select the “Behavior” tab.
- Check the box that says “Include a Delete command that bypasses Trash.”
This will add “Delete” to the right-click menu so you can delete files without using the keyboard shortcuts.
Method 2: Using Nautilus Scripts for Secure Deletion
You can also create custom scripts for Nautilus to integrate commands like srm
.
-
Open your terminal and go to the Nautilus scripts directory:
cd ~/.local/share/nautilus/scripts/
-
Create a new script called
Secure_Delete
:vim Secure_Delete
-
Add these lines to the script:
#!/bin/bash srm -r $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
The
$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
variable gives the paths of whatever you have selected in Nautilus. -
Save the file and exit the editor (in vim, hit
ESC
, then type:wq
). -
Make the script executable:
chmod +x Secure_Delete
-
Now, in Nautilus, right click on a file or folder, go to “Scripts”, and select “Secure_Delete” to use the
srm
command.
You can make similar scripts for shred
or other secure delete tools. There are also GUI tools like Nautilus Wipe and BleachBit which provide more complete GUI options for file deletion.