Delete files permanently with shred command in Linux – Remove absolutely

terminal-logo-small

Sometimes need to delete files whose contents should disappear absolutely, completely and safely. Linux command rm just remove file and it is still possible to dig out from the disk. Fortunately for Linux can be found in shred program that removes the files permanently. Shred command is easy and quickly to use cases when files need to deleted forever.

Shred command usage

Create test file:

echo "testing testing" > /tmp/test.txt

Delete file with shred command:

shred -v -n 25 -u -z /tmp/test.txt

Output:

shred: /tmp/test.txt: pass 1/26 (random)...
shred: /tmp/test.txt: pass 2/26 (dddddd)...
shred: /tmp/test.txt: pass 3/26 (b6db6d)...
shred: /tmp/test.txt: pass 4/26 (eeeeee)...
shred: /tmp/test.txt: pass 5/26 (888888)...
shred: /tmp/test.txt: pass 6/26 (111111)...
shred: /tmp/test.txt: pass 7/26 (222222)...
shred: /tmp/test.txt: pass 8/26 (924924)...
shred: /tmp/test.txt: pass 9/26 (aaaaaa)...
shred: /tmp/test.txt: pass 10/26 (555555)...
shred: /tmp/test.txt: pass 11/26 (333333)...
shred: /tmp/test.txt: pass 12/26 (6db6db)...
shred: /tmp/test.txt: pass 13/26 (random)...
shred: /tmp/test.txt: pass 14/26 (cccccc)...
shred: /tmp/test.txt: pass 15/26 (444444)...
shred: /tmp/test.txt: pass 16/26 (999999)...
shred: /tmp/test.txt: pass 17/26 (db6db6)...
shred: /tmp/test.txt: pass 18/26 (000000)...
shred: /tmp/test.txt: pass 19/26 (492492)...
shred: /tmp/test.txt: pass 20/26 (666666)...
shred: /tmp/test.txt: pass 21/26 (777777)...
shred: /tmp/test.txt: pass 22/26 (249249)...
shred: /tmp/test.txt: pass 23/26 (bbbbbb)...
shred: /tmp/test.txt: pass 24/26 (ffffff)...
shred: /tmp/test.txt: pass 25/26 (random)...
shred: /tmp/test.txt: pass 26/26 (000000)...
shred: /tmp/test.txt: removing
shred: /tmp/test.txt: renamed to /tmp/00000000
shred: /tmp/00000000: renamed to /tmp/0000000
shred: /tmp/0000000: renamed to /tmp/000000
shred: /tmp/000000: renamed to /tmp/00000
shred: /tmp/00000: renamed to /tmp/0000
shred: /tmp/0000: renamed to /tmp/000
shred: /tmp/000: renamed to /tmp/00
shred: /tmp/00: renamed to /tmp/0
shred: /tmp/test.txt: removed

Options used:

-v  ## Verbose
-n  ## Overwrite n times
-u  ## Truncate and remove file after overwriting
-z  ## add a final overwrite with zeros to hide shredding

CAUTION: Note that shred relies on a very important assumption: that the file system overwrites data in place. This is the traditional way to do things, but many modern file system designs do not satisfy this assumption. The following are examples of file systems on which shred is not effective, or is not guaranteed to be effective in all file system modes:

  • log-structured or journaled file systems, such as those supplied with AIX and Solaris (and JFS, ReiserFS, XFS, Ext3, etc.)
  • file systems that write redundant data and carry on even if some writes fail, such as RAID-based file systems
  • file systems that make snapshots, such as Network Appliance’s NFS server
  • file systems that cache in temporary locations, such as NFS version 3 clients
  • compressed file systems

In the case of ext3 file systems, the above disclaimer applies (and shred is thus of limited effectiveness) only in data=journal mode, which journals file data in addition to just metadata. In both the data=ordered (default) and data=writeback modes, shred works as usual. Ext3 journaling modes can be changed by adding the data=something option to the mount options for a particular file system in the /etc/fstab file, as documented in the mount man page (man mount).

More info about options with command:

man shred
Follow If Not True Then False Updates!
Add Comment Register



Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>