Learn the Proper Use of the Linux Shred Command

When you don't want anyone to see the files you delete

Document emerging from paper shredder

 Zigy Kaluzny / Getty Images

Shred is one of four Linux commands that sound similar but are not the same: shred, wipe, delete, and erase.

You use shred when you want to erase a single piece of data permanently. The information, which you identify, is overwritten by 1s and 0s several times, which permanently erases the data. This is unlike the other similar commands that erase data but leave it retrievable under certain circumstances.

With the shred command, you can shred a small collection of files whenever you want. It is an easy way to erase data you don't want anyone to be able to unerase. Ever.

Options When Using the Shred Command

Use the Shred command to overwrite the specified files repeatedly and make it difficult or impossible for even expensive hardware or software to recover the data. Available options include:

  • -f changes permissions to allow writing if needed
  • -n  (iterations=N) overwrites N times instead of the default, which is three times
  • -s  (size=N) specifies the number of bytes to shred
  • -u  truncates and removes files after overwriting
  • -v  shows verbose information about the progress
  • -x  does not round file sizes up to the next full block
  • -z adds a final overwrite with zeros to hide shredding
  • -u  removes the file after overwriting

Examples of the Shred Command

To enter the names of the exact files you want to shred, use the following format:

If you add the option -u, the listed files are shredded and also deleted to free up space on your computer.

Places Shred Doesn't Work

Shred relies on an important assumption — that the file system overwrites data in place. This is traditional, but some file systems do not satisfy this assumption. The following are examples of file systems on which shred is not effective:

  • Log-structured or journaled file systems, such as those supplied with AIX and Solaris (and JFS, ReiserFS, XFS, and Ext3)
  • 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

Also, file system backups and remote mirrors may contain copies of the file that cannot be removed, and that could allow a shredded file to be recovered later.