Linux and Unix shred command
Use shred to overwrite a file to hide its contents, and optionally delete it.
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 simply 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 that you thought you had deleted.
The analogy is that of a paper shredder. If you simply 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. If you really want 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 many times as you specify) the data you want to destroy, replacing it with other (usually random) data. This magnetically destroys the data on the disk and makes it highly improbable that it can ever be recovered.
shred [OPTIONS] FILE [...]
|-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|
After destroying the FILE data, shred will also delete 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 a very important assumption: that the file system overwrites data "in-place." This 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.
In addition, file system backups and remote mirrors may contain copies of the file that cannot be removed, and that will allow a shredded file to be recovered later.
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.
Overwrite all data on the partition /dev/hda6.
rm — Delete files.