LinuxCommandLibrary

shred

Overwrite files to prevent data recovery

TLDR

Overwrite a file

$ shred [path/to/file]
copy

Overwrite a file and show progress on the screen
$ shred [[-v|--verbose]] [path/to/file]
copy

Overwrite a file, leaving zeros instead of random data
$ shred [[-z|--zero]] [path/to/file]
copy

Overwrite a file a specific number of times
$ shred [[-n|--iterations]] [25] [path/to/file]
copy

Overwrite a file and remove it
$ shred [[-u|--remove]] [path/to/file]
copy

Overwrite a file 100 times, add a final overwrite with zeros, remove the file after overwriting it and show verbose progress on the screen
$ shred [[-vzun|--verbose --zero --remove --iterations]] 100 [path/to/file]
copy

SYNOPSIS

shred [OPTION]... FILE...

PARAMETERS

-f, --force
    Change permissions to allow writing if necessary.

-n N, --iterations=N
    Overwrite N times instead of the default (3).

-u[HOW], --remove[=HOW]
    Truncate and remove the file after overwriting. HOW can be 'unlink', 'wipe', or 'wipesync'.

-v, --verbose
    Show progress and details of the shredding process.

-z, --zero
    Add a final overwrite with zeros to hide the shredding process.

-x, --exact
    Do not round file sizes up to the next full block. (This is often the default for modern shred versions).

-s N, --size=N
    Shred N bytes. Suffixes K, M, G, T are accepted (e.g., 10M for 10 megabytes).

--random-source=FILE
    Get random bytes from FILE instead of the default /dev/urandom.

DESCRIPTION

shred is a command-line utility in Linux designed to securely delete files. Unlike the standard rm command, which only removes the file's directory entry, shred overwrites the file's data multiple times with pseudo-random patterns. This process makes it significantly more difficult, if not impossible, to recover the original data using forensic data recovery techniques. It's crucial for protecting sensitive information before disposing of storage media or sharing a system. The number of overwriting passes can be specified, and it also includes options to zero out the last overwrite and/or remove the file after shredding. While generally effective for traditional magnetic hard drives, its utility can be limited on certain modern file systems and storage devices.

CAVEATS

shred's effectiveness can be significantly limited or entirely ineffective in several scenarios:

Journaling and Copy-on-Write Filesystems: Filesystems like ext3, ext4, XFS, JFS, and NTFS, or those with copy-on-write features (e.g., Btrfs, ZFS), may keep copies of data or metadata in different locations, making recovery possible even after shredding.

Solid State Drives (SSDs) and Flash Memory: Due to wear-leveling algorithms, SSDs and USB flash drives often relocate data blocks internally. This means shred might overwrite a new block, leaving the original data block containing the sensitive information untouched.

RAID, NAS, and Distributed Filesystems: Data stripping, replication, and distributed storage mechanisms can mean copies of data exist elsewhere on the system, making file-level shredding insufficient.

Cached Data and Swap Space: Data might exist in the operating system's cache, swap space, or application-specific temporary files, which shred does not target.

Backup Systems: Previous versions of the file might exist in local or remote backup systems.

Metadata Retention: shred primarily targets file content, not all associated metadata. While the file's content is overwritten, some metadata (like filenames or directory structure entries) might persist until the space is reused.

EFFECTIVENESS ON MODERN STORAGE

While shred is effective on traditional magnetic hard drives, its utility is significantly reduced on modern storage like SSDs, RAID arrays, and journaling file systems due to their internal data management strategies (wear leveling, copy-on-write, journaling). For these, hardware-level secure erase commands (e.g., ATA Secure Erase) or full disk encryption are more reliable for data sanitization.

ALTERNATIVES FOR DISK SANITIZATION

For entire disk or partition sanitization, tools like dd (writing /dev/zero or /dev/urandom directly to the whole device) or dedicated disk wiping utilities (often provided by disk manufacturers or specialized software) are more appropriate and effective than applying shred to individual files on the entire device.

HISTORY

shred is a core utility included in the GNU Core Utilities (`coreutils`), which are fundamental tools found in all GNU/Linux distributions. Its development has focused on providing a robust and accessible method for secure file deletion, evolving with considerations for various storage technologies. It has been a standard utility for many years, addressing the need for data sanitization beyond simple file unlinking, and continues to be maintained as part of the essential GNU toolkit.

SEE ALSO

rm(1), dd(1), wipe(1), scrub(1), srm(1) (often part of secure-delete package)

Copied to clipboard