shred Command in Linux with Examples

This tutorial explains Linux “shred” command, options and its usage with examples.

shred – delete a file securely, first overwriting it to hide its contents


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 (25)
-s, –size=N
shred this many bytes (suffixes like K, M, G accepted)
-u, –remove
truncate and remove file after overwriting
-v, –verbose
show progress
-x, –exact
do not round file sizes up to the next full block
-z, –zero
add a final overwrite with zeros to hide shredding

shred standard output

Note: Join free Sanfoundry classes at Telegram or Youtube

Note: Delete FILE(s) if –remove (-u) is specified. The default is not to remove the files because it is common to operate on device files like /dev/hda, and those files usually should not be removed. When operating on regular files, most people use the –remove option.


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

$ shred file1.txt file2.jpg file3.doc

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

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

3. Overwrite a partition

shred /dev/hda6

Overwrite all data on the partition /dev/hda6.

4. To see what shred is actually doing, give it the verbose -v option:

$ shred -u -v private.txt
shred: private.txt: pass 1/25 (random)...
shred: private.txt: pass 2/25 (cccccc)...
shred: private.txt: pass 3/25 (111111)...
shred: private.txt: pass 4/25 (000000)...
shred: private.txt: pass 5/25 (999999)...
shred: private.txt: pass 6/25 (aaaaaa)...
shred: private.txt: pass 7/25 (924924)...
shred: private.txt: pass 8/25 (b6db6d)...
shred: private.txt: pass 9/25 (6db6db)...
shred: private.txt: pass 10/25 (888888)...
shred: private.txt: pass 11/25 (492492)...
shred: private.txt: pass 12/25 (db6db6)...
shred: private.txt: pass 13/25 (random)...
shred: private.txt: pass 14/25 (ffffff)...
shred: private.txt: pass 15/25 (bbbbbb)...
shred: private.txt: pass 16/25 (777777)...
shred: private.txt: pass 17/25 (444444)...
shred: private.txt: pass 18/25 (dddddd)...
shred: private.txt: pass 19/25 (333333)...
shred: private.txt: pass 20/25 (555555)...
shred: private.txt: pass 21/25 (222222)...
shred: private.txt: pass 22/25 (eeeeee)...
shred: private.txt: pass 23/25 (666666)...
shred: private.txt: pass 24/25 (249249)...
shred: private.txt: pass 25/25 (random)...
shred: private.txt: removing
shred: private.txt: renamed to 00000000000
shred: 00000000000: renamed to 0000000000
shred: 0000000000: renamed to 000000000
shred: 000000000: renamed to 00000000
shred: 00000000: renamed to 0000000
shred: 0000000: renamed to 000000
shred: 000000: renamed to 00000
shred: 00000: renamed to 0000
shred: 0000: renamed to 000
shred: 000: renamed to 00
shred: 00: renamed to 0
shred: private.txt: removed

5. This will overwrite the data on the drive with garbage using 30 passes

 shred -u -n 30 /dev/hda

The drive will need to be re-formatted after this as even the filesystem structure will be destroyed.

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.

If you find any mistake above, kindly email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.