Last Updated : 10 Jun, 2023
When you delete a file from Linux or from any Operating System, 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 on 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 a 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 of the `shred` command in Linuxshred [OPTION] FILE
[OPTIONS] represents the various parameters and flags that can be used to modify the behavior of the Shred command
FILE refers to the file or files you wish to shred.
Options available in `shred` Command Options Description -n, --iterations=NThis option allows you to specify the number of times the file will be overwritten during the shredding process. By default, Shred performs 3 iterations.
-u, --removeThis option instructs Shred to remove the file after the shredding process is complete.
-v, --verboseWhen using this option, Shred provides detailed information about the shredding process.
-z, --zeroThis option adds a final overwrite of all zeros to the file after the shredding process is complete. This helps to hide the fact that the file has been shredded.
-f, --forceThis option forces Shred to shred files that have read-only permissions or are otherwise protected.
-r, --random-source=FILEWith this option, you can specify a file as the source of random data for overwriting the file being shredded.
Examples and Usage of the `shred` command in Linux 1. Overwrite the contents of the file multiple times to make it unrecoverable.shred filename.txt
The `filename.txt` will be overwritten during the shredding process.
To-overwrite-the-contents-of-the-file-multiple-times-to-make-it-unrecoverableIt 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. `-n, --iterations=N` option in `shred` commandTo change the number of times a file is to be overwritten. By default, Shred performs 3 iterations but with this option we can define the number of iterations.
shred -n 10 filename.txtTo-change-the-number-of-times-a-file-is-to-be-overwritten
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. `-u, --remove` option in `shred` commandTo remove the file after the shredding process is complete.
shred -u filename.txtTo-overwrite-and-delete-a-file-as-well
This will overwrite the file many times 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.txtTo-overwrite-some-specific-bytes-of-text-only
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. `-v, --verbose` option in `shred` commandTo run shred command with verbose mode or to get how many times the file is overwritten
shred -v filename.txtTo-run-shred-command-with-verbose-mode
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. `-f, --force` option in `shred` commandTo change permissions to allow writing if necessary while using shred command.
shred -f filename.txtTo-change-permissions-to-allow-writing-if-necessary-while-using-shred-command
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. `-z, --zero` option in `shred` commandTo add a final, overwrite with zeros to hide shredding.
shred -z filename.txt`To-add-a-final-overwrite-with-zeros-to-hide-shredding
After completing the shredding, it will overwrite the 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. `--version` option in `shred` commandTo get basic details and version of shred command.
shred --versionTo-get-basic-details-and-version-of-shred-command
This will display the version of the shred command present in your system along with some copyright details.
ConclusionIn this article we have discussed about `shred` command in Linux which provides a reliable and effective way for securely deleting files that can't be recovered further. We learn that overwriting file content multiple times ensures that our data cannot be easily retrieved. We have also discussed various options in `shred` command.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4