Linux shred command

Updated: 11/06/2021 by Computer Hope
shred command

On Linux operating systems, the shred to overwrite a file to hide its contents, and optionally delete it.

The shred program was created by the GNU project. On non-Linux operating systems, it has the command name gshred.

Description

shred is a program that will overwrite your files in a way that makes them very difficult to recover by a third party.

Normally, when you delete a file, that portion of the disk is marked as being ready for another file to be written to it, but the data is still there. If a third party were to gain physical access to your disk, they could, using advanced techniques, access the data you thought you had deleted.

The analogy is that of a paper shredder. If you crumple up a piece of paper and throw it in the trash can, a third party could come along, root through your trash, and find your discarded documents. To destroy the document, it's best to use a paper shredder. Or burn it, I suppose, but that's not always practical in a typical office.

The way that shred accomplishes this type of destruction digitally is to overwrite (over and over, repeatedly, as often as you specify) the data you want to destroy, replacing it with other (usually random) data. Doing this magnetically destroys the data on the disk and makes it highly improbable that it can ever be recovered.

Syntax

shred [OPTIONS] FILE [...]

Options

-f, --force Change permissions to allow writing if necessary.
-n, --iterations=N Overwrite N times instead of the default (3).
-s, --size=N Shred this many bytes (suffixes like K, M, G accepted).
-u, --remove Truncate and remove file after overwriting.
-v, --verbose Show verbose information about shredding progress.
-x, --exact Do not round file sizes up to the next full block; this is the default for non-regular files such as device names.
-z, --zero Add a final overwrite with zeros to hide shredding.
- Shred standard output.
--help Display this help and exit.
--version Output version information and exit.

Notes

After destroying the FILE data, shred also deletes the FILE(s) if --remove (-u) is specified. The default is not to remove the files because it is common to operate on entire device files like /dev/hda, and those files usually should not be removed. When operating on regular files, most people use the --remove option.

Caution

Take note that shred relies on an important assumption: that the file system overwrites data "in-place." This assumption is the traditional way to do things, but many modern file systems do not do things exactly this way.

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 file 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 manual.

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

Examples

shred file1.txt file2.jpg file3.doc

Overwrite the data of file1.txt, file2.jpg, and file3.doc using the default shredding methods.

shred -u file1.txt file2.jpg file3.doc

Same as above, but also delete those three files, freeing up that space on the disk for later use.

shred /dev/hda6

Overwrite all data on the partition /dev/hda6.

rm — Delete files.