shred command in Linux with Examples
When you delete a file from Linux or from any os, then the file is not deleted permanently from the hard disk. When a file is deleted it first gets moved to the trash and as soon as you clear off the trash the files get deleted for the file system. But the file is still there in your hard drive and it could be recovered.
When you delete a file permanently or delete it from the trash, the pointer pointing to the file leaves the address of it and the data of the file is sent to a sector in hard disk and is considered as unallocated space and it can be recovered easily. The file gets permanently deleted when the OS writes over the sector of the file which was considered as unallocated. So, in order to delete a file completely from hard disk “shred” is used in Linux. This command overwrites the contents of a file multiple times, using patterns chosen to maximize the destruction of the residual data, making it harder for even very expensive hardware probing to recover it.
Syntax:
shred [OPTION]... FILE...
Working with shred command
1. To overwrite the contents of the file multiple times to make it unrecoverable.
$shred filename.txt
It will change the file data in such a way that it would be really hard to get the old file back.
Note: In this case, The name of the file is filename.txt you may change it as per your need.
2. To change the number of times a file is to be overwritten.
$shred -n 10 filename.txt
This command will overwrite the file 10 times.
Note: In this case, the number of times the file is to be shredded is set to be 10 and the name of the file is filename.txt you may change these as per your need.
3. To overwrite and delete a file as well.
$shred -u filename.txt
This will overwrite the file many time and will delete it as well.
Note: In this case, The name of the file is filename.txt you may change it as per your need.
4. To overwrite some specific bytes of text only.
$shred -s 5 filename.txt
This will overwrite the first 5 bytes of the file.
Note: In this case, The name of the file is filename.txt and the number of bytes is 5, you may change these as per your need.
5. To run shred command with verbose mode or to get how many times the file is overwritten
$shred -v filename.txt
It will display every time it overwrites the file.
Note: In this case, The name of the file is filename.txt you may change it as per your need.
6. To change permissions to allow writing if necessary while using shred command.
$shred -f filename.txt
When you run shred command with -f option it will write the file even by changing the permissions if necessary.
Note: In this case, The name of the file is filename.txt you may change it as per your need.
7. To add a final overwrite with zeros to hide shredding.
$shred -z filename.txt`
After completing the shredding it will overwrite file with zeros to hide shredding.
Note: In this case, The name of the file is filename.txt you may change it as per your need.
8. To get basic details and version of shred command.
$shred --version
This will display the version of the shred command present in your system along with some copyright details.
Please Login to comment...