Files and folders

The shred command

Overwrites a file several times with random data before deleting it, to make recovery harder. Designed for magnetic disks; on SSDs and systems with automatic copies it guarantees nothing.

Syntax

shred [opciones] archivo...Try it in the terminal →

Most useful options

-n NNumber of random passes. The default is 3
-zAdds a final pass of zeros to hide that shred was used
-uDeletes the file after overwriting it
-xDoes not round the size up to the next full block. By default the file can grow

Copy-ready examples

$ shred -v -n 3 informe.txtthree random passes, with visible progress. The file still exists when it finishes.

Example output

shred: informe.txt: pass 1/3 (random)...
shred: informe.txt: pass 2/3 (random)...
shred: informe.txt: pass 3/3 (random)...
$ shred -u -z secreto.txtoverwrites the file, adds a pass of zeros and then deletes it.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
shred: nonexist: failed to open for writing: No such file or directoryThe file does not exist or the name is misspelled.Check the path with ls before overwriting anything.
shred: invalid number of passes: 'abc'The value given to -n is not a whole number.Write digits only, for example -n 3.
shred: carpeta: failed to open for writing: Is a directoryshred works with files, not with directories.Find the files with find and pass them to shred one by one.

Typical mistakes

  • shred -u deletes the file, but it does not remove copies in backups, snapshots or sync history.
  • Without -x, the file can end up larger than the original, because it is rounded up to the next block.
  • If the process is interrupted halfway, the file is left partly overwritten. Run it again.

Differences from similar commands

  • rm: removes only the directory entry. The data stays on disk and can be recovered. shred tries to overwrite it first.
  • dd: copies blocks and can overwrite a whole device with zeros or random data. It is more general, but it does not delete files.
  • truncate: changes the size of a file without overwriting its content. It can empty a file, but it does not delete it securely.

Security

shred is not reliable on SSDs: the controller spreads writes across different cells and may leave copies of the data. It is also not reliable on journaling or copy-on-write systems, such as btrfs or ZFS, where the old data may remain in the journal or in a snapshot. Copies in the cloud or in backups remain too. For disks, use full-disk encryption from the start.

Related commands

FAQ

Does shred really delete a file?

On a classic magnetic disk it makes recovery much harder. On SSDs, copies and journaling systems there is no guarantee.

How many passes do I need?

On modern disks a single random pass is usually enough. The three passes by default are a historical value.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course