Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there a way to make sure that a deleted file can not be recovered?

As you know, deleting a file by pressing shift-del or using trash doesn't mean that file is gone forever. It resides somewhere in the computer.

In day to day life, law enforcement or thieves use recovery programs to reveal our private data or something else.

They can recover all data that resides on hard disk, in RAM, and even USB.

To protect us from these people, what should one do? Which program should one use?

Note: I don't want an answer like first use a recovery program then erase that file with shred. With just one program, I want to erase all unused/deleted files on my computer.

share|improve this question
So do you want that at any point of time, you are able to run one command across a directory or filesystem that is able to wipe out any traces of files that have been previously deleted with a simple 'rm' command? –  bitwelder Aug 20 '11 at 8:18
Full disk encryption protects you against thieves providing you've a good passphrase set. –  Lekensteyn Aug 20 '11 at 9:45
@fatai - please can you highlight in your question what is the remaining issue. One bounty has been already offered and given - its not clear why another has been offered. –  fossfreedom Sep 1 '11 at 11:24
@fossfreedom. not for question. Boutry for the answer –  user20296 Sep 3 '11 at 18:15
add comment

8 Answers

up vote 56 down vote accepted


This command line tool is already installed from core utilities in Ubuntu to securely erase and overwrite single files by using the Gutman method.

Fast shredding

shred -vzn 0 /dev/sdc1

erases whole partitions by overwriting everything with 0s in a single iteration. If no legal aspects require another procedure doing so is most probably safe to securely delete your private data Craig Wright Lecture Notes in Computer Science, 2008, 5352, 243-257.

Secure shredding

shred -vzn 3 /dev/sdc1

erases the whole partition using 3 iterations with random numbers. In addition (option -z) writes zeros to hide the shredding process at the end. This will take 4 times longer than the fast method.

NOTE: By shredding a partition we will overwrite this partition with 0 or random numbers. It therefore efficiently deletes everything including file system caches on that partition forever. This can also be used to remove unwanted remnants of deleted files. Files we want to keep will have to be backed up before shredding.

Wipe Install wipe

More options and the possibility to erase directories in addition to a single file is offered by this command line utility.

Additional notes on journaling file systems and SSD:

  • Please read the notes in the linked manpages on security issues arising from still recoverable backups in journaling file systems when erasing single files. Overwriting whole partitions rather than single files will effectively erase all data even when using a journaling file system.

  • Erasing data on a solid state disk (SSD) can if at all only be done by overwriting the whole drive (not only single partitions) with several iterations. Some SSDs may have an inbuilt feature to erase data but this may not always be efficient (see this link from comment). At present there is no general recommendation on the wiping processes or number of erase iterations needed to securely remove all data remnants on all SSDs available.

These options can be added in the context menu of Nautilus and Thunar.

  • In Thunar, open "Edit" then "Configure Custom Actions"

Add (the plus sign)

Name "Shred File"

Description whatever you like

Action "shred -u %f"

Similarly for wipe.

Select "Appearance Conditions" and select "Other Files"

share|improve this answer
It is probably also worth noting that if you're using a solid state drive, it also acts as a simple log structured file system and may not overwrite the data. –  James Henstridge Aug 18 '11 at 8:58
@shred, "about 20 minutes to erase a 1.44MB". About whole life to erase 640 gb :) . For wipe, "... we cannot guarantee that wipe will actually erase data, or that wiped data is not recoverable by advanced means." In other words, wipe has no real/full power on memory. –  user20296 Aug 20 '11 at 7:50
Note that, while you can use shred on individual files, as well, if you use a modern journaling filesystem, there's no guarantee that shred will result in unrecoverable deletion. You'd have to blow away the entire partition. I think the US government standard is 7 passes with random data. –  Scott Severance Aug 24 '11 at 2:44
One comment regarding SSD: Overwriting the whole drive will not really help. In short: You cannot reliably remove data from flash memory. Always store confidential files encrypted. (cf. Wei et al., Reliably Erasing Data From Flash-Based Solid State Drives: usenix.org/events/fast11/tech/full_papers/Wei.pdf) –  freddyb Aug 26 '11 at 10:19
@freddyb: I am aware of the fact that at present it is not clear how to securely erase data from a SSD. Encryption is always better - this includes conventional drives as well! The question however was on how to securely erase data (implying they may not have been encrypted before). –  Takkat Sep 1 '11 at 14:18
show 6 more comments

There isn't one command that you can run which will easily clean up all the already-deleted files for you. However, there are a number of things you can do to reduce your vulnerability to this sort of attack in future.

As others have said, using tools like shred or srm allows you to delete a specific file by actually overwriting it, rather than just removing it from the filesystem. If you're feeling bold, you can replace the rm command with shred or srm to securely delete files going forward. That means that whenever you (or another program) tries to delete something using rm, the secure delete command will run instead.

However, if you're using a solid state disk, or even some newer mechanical disks, shred and other overwriting-based methods may not be effective, since the disk may not actually write where you think it's writing (source).

Full-Disk Encryption

A more convenient option is full-disk encryption. If you use the alternate installer, Ubuntu can automatically set up a fully-encrypted disk for you you, but you can also customize and configure the settings yourself. Once installed, the encryption is almost invisible to you: after you enter the passphrase (be sure to pick a good, long one) when the computer starts up, everything looks and feels just like normal Ubuntu.

You can also encrypt external media like USB drives using Ubuntu's Disk Utility. Setting up an encrypted external disk is as simple as checking the "encrypt underlying filesystem" box when formatting the disk. You can even store the passphrase on your (encrypted) keyring, so that you don't need to enter the phrase every time you plug that disk into your computer.

If your whole disk -- and all your removable media -- is encrypted, there's much less to worry about. A thief or police officer would need to swipe your computer while it's on, (or within a minute or two of turning it off if they're very good) in order to access your data. If you hibernate (rather than suspend) your computer when it's not in use, then you should be pretty safe.

If you ever need to completely destroy all your data, you don't need to do a Gutmann wipe of your whole disk. Simply overwrite the very beginning of the disk, to destroy the headers for the encrypted volume. Unlike with a regular filesystem, this will actually make it impossible to recover the data.

So, how do you go from your current setup to a safely encrypted disk? It's quite a challenge to retrofit a currently-installed operating system to use an encrypted disk. The easiest approach is to backup all your data and settings, then reinstall with an encrypted disk. When backing up, make sure to back up your data to an encrypted external drive, but don't save the passphrase in your keyring.

After you've backed everything up, you may want to aggressively wipe your hard drive, to make sure that none of your existing data can be recovered in the future. If you're using an SSD, the process is even more challenging, so depending how much you want to invest in the process, it might be worth destroying your current disk (a challenging proposition) and starting with a new one.

When reinstalling the OS, if you haven't aggressively wiped the disk already, you should make sure to completely fill the new encrypted partition, which will overwrite all your old data. Once you've restored your backup, you may want to aggressively wipe the start of the backup disk, to destroy the encryption header, so that it can't be recovered again.

share|improve this answer
Can you explain the part about 'Simply overwrite the very beginning of the disk, to destroy the headers...'? I've always just discarded or returned encrypted drives when they failed, assuming nobody could recover the data. Is this a bad assumption? This is with 64 character random hex passwords, so nobody is cracking them. –  Tom Brossman Feb 17 '12 at 14:12
add comment

First, delete files with rm on the terminal or with shift-delete on nautilus. Better yet, use srm, from the the Secure-Delete tools.

You can install the secure delete tools like this:

apt-get install secure-delete

Second, use sfill to wipe out unused space on your disk:

sudo sfill -f <directory>

This will take some time, since it is using crypto techniques to fill out the disk.

Warning: this is going through your whole filesystem, and you are root. Use with care!

This will create a file which wipes out all previously existing data. The file will be created in <directory>.

share|improve this answer
this program spends too much time. For 80 gb, I have waited approximately 18 hours. Moreover, there is no tool showing progress. –  user20296 Aug 18 '11 at 8:35
I forget to add ; 18 hours for just filling disk with /000.0 files –  user20296 Aug 18 '11 at 15:42
but it's secure and you can delete a file or directory. –  RusAlex Aug 23 '11 at 8:37
I question whether this is really secure. On modern filesystems (ext2/3/4, ntfs, etc), there is a journal that helps prevent accidental data loss. So, even if you wipe the free space, you can't guarantee that the file is removed from the journal. Also, I understand that some filesystems work at high enough a level that it's difficult to guarantee that you're actually overwriting the physical disk sectors that were written to. AFAIK, the only way to securely wipe something is to wipe the entire partition and all files on it. –  Scott Severance Aug 24 '11 at 2:48
add comment

If I read you right, you want to erase all your previously deleted files. Here is a simple way to do that:

$ dd if=/dev/zero of=/path/to/mounted/partition/tmp_file bs=1M count=999999999999

Let that run till it complains till it gets a disk write error [out of space]. Then delete the file! What this does is just fill up your empty disk with 000s, so all your previous files get overwritten. Make sure to delete the file now, or you will not have any disk left. You might want to do this a few times if you are really paranoid. Or if you want to write random to your disk, I'd suggest replace /dev/zero with /dev/urandom.

However, this will take much much longer, so I'd run it overnight. Also, if you want a progress meter, do this instead:

$ free=$( df {PARTITION OR MOUNTPOINT}  |awk '{print $3}'|tail -1 )
$ dd if=/dev/zero bs=1M count=999999999999 | pv -s "$free" > /path/to/mounted/partition/tmp_file

First you are getting your free disk space with du, awk, and tail, then using dd to get /dev/zero, piping that to pv which stands for "pipe viewer", that redirects everything to tmp_file Once again, delete the file afterwards. $ rm tmp_file

Anyway, hope someone finds this useful! :)

share|improve this answer
add comment

A GUI program for this is BleachBit (it's also in the sources). More recent (deb file) version at the BleachBit Sourceforge page.

Beyond simply deleting files, it includes advanced features such as shredding files to prevent recovery, wiping free disk space to hide traces of files deleted by other applications.

"BleachBit quickly frees disk space and tirelessly guards your privacy. Free cache, delete cookies, clear Internet history, shred temporary files, delete logs, and discard junk you didn't know was there. Designed for Linux and Windows systems, it wipes clean 90 applications including Firefox (vacuuming to make it faster), Internet Explorer, Adobe Flash, Google Chrome, Opera, Safari and more." (from http://bleachbit.sourceforge.net/)

BleachBit has several advanced cleaners:

  • Clear the memory and swap on Linux
  • Delete broken shortcuts on Linux
  • Delete the Firefox URL history without deleting the whole file—with optional shredding
  • Find widely-scatted junk such as Thumbs.db and .DS_Store files.
  • Delete the OpenOffice.org recent documents list without deleting the whole Common.xcu file
  • Overwrite free disk space to hide previously files
  • Vacuum Firefox, Google Chrome, Liferea, Thunderbird, and Yum databases: shrink files without removing data to save space and improve speed
  • Surgically remove private information from .ini and JSON configuration files with deleting the whole file

For details on how to use Bleachbit to delete securely specific files and folders see this answer.

share|improve this answer
add comment

I would say the the solution is a combination of several answers given here. For already-deleted files and partitions still in use, I agree with Matt.

Then, for the future I would suggest to start using secure-delete tools instead of simple 'rm'.

Last, when it will be possible to reformat the partition, the option of encrypt the partition should be considered. Perhaps using some approach that offers Plausible deniability like in Truecrypt

share|improve this answer
add comment

I use truecrypt file image for such essential data. I't handy, free, crossplatform and I don't need a full disk nor using any extra software to "really delete" the file.

Just make sure you have strong password and make make backup of the image file. I keep backup in a cloud.

share|improve this answer
add comment

If you want a solution which can't be thwarted by a pathologically obsessed individual then you should consider some combination (limited by monetary resources) of:

  • degaussing -- magnetically erasing the hard drive
  • physically disabling the hard drive -- i.e. industrial hole punch
  • acid bath <-- you can't get bits from a pile of goo.

These solutions range drastically in cost & ingenuity. A few:

share|improve this answer
Fun answer, but I think the asker would like to be able to keep using his hard drive after his deletions. –  WarriorIng64 Sep 2 '11 at 15:49
where's a will there's a way: why not an atomic bomb? –  cipricus Mar 14 '13 at 21:07
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.