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

Related posts:

  1. Delete files securely on Linux – Journaled file systems Few days ago I write about shred, which work fine for old systems, like EXT2, but not so nice with...
  2. Linux Tip: How to handle a files with a dash as first character from command line Sometimes you maybe have to handle files with a dash (-) as first character from Linux command line. It can...
  3. Linux locate command: Find Files and Directories Quickly and Efficiently This is quick guide howto find files and directories quick and efficiently on Linux with locate command. Linux find command...
  4. Google search from Linux and UNIX command line Today I started thinking that how cool is do some Google searches straight from command line. First I try to...
  5. Linux: Enable Laptop Touchpad Vertical Scrolling and Tapping from Command Line I noticed that the Fedora Linux with KDE desktop, has reasonably poor support for laptop touchpad adjustment. For example, the...

About the Author

Hi, I'm JR and the Founder of if not true then false. I am a software developer, and I have over ten years experience in programming. I'm big fan of Linux and Open Source. And normally I use just Linux environments.

Like If (!1) 0 on Facebook: