Introduction to Linux Shred
The Linux shred command; will overwrite the file in such a way that the third-party tool or software will not able to recover the data from the same shred file. It is the safer way to destroy the critical data or information and you don’t want to allow the recovery of data at any point in time.
The Linux shred command-line utility was written by Colin Plumb.
Syntax of Shred command
shred [ OPTION ]... [ FILE ]...
- Shred: The free keyword in the command | syntax. It will take two sets off an argument as an option and the file name to shred the data.
- OPTION: We can provide the different flags as options that are compatible with the shred command.
- FILE: Input file to provide the shred command
How does Linux Shred Command work?
In most of the operating systems, when we are deleting any file or data from standard HDD the data is not deleting permanently as per the standard time. If anyone gets the same HDD and tries to recover the data or file (without shred) then with the help of a third-party application or tool we are able to recover the deleted data from the HDD.
The shred command accepting the different valid flag option in shred command and overwrite the data as per the provided input file.
Note: Please make sure that you will trigger the shred command very carefully. If you will shred the file accidentally then the recovery of file data is so difficult.
There are a few different types of shred option available in the Linux ecosystem.
|Sr. No||Shred Option||Option Meaning||Description|
|1||-f,||–force||if necessary, It will change the permissions to allow writing|
|2||-n||–iterations||By default, shred command shred the file 3 times. We can provide the user input to overwrite the “N” number of times|
|3||–random-source||Especially for file||It will get the random bytes from FILE|
|4||-s||–size||It will shred this many bytes|
|5||-u||–remove||It will truncate and remove after overwriting the files|
|6||-v||–verbose||It will display the live process|
|7||-x||–exact||It will don’t round file sizes up to the next full block|
|8||-z||–zero||To hide shredding, it will add a final overwrite with zeros|
|9||–help||Help Option||It will display the help option|
|10||–version||Version Information||It will display the output version information|
Examples of Linux Shred
Here are the following examples mention below
Example #1 – Shred Command
The simple Linux shred command is just overwriting the input file data. It is the simplest command in the shred command family. It will run with default parameters of the shred command.
cat file.txt | grep ^t
We are having a sample directory, in the same directory there is filename “file.txt”. There are records/lines in it (refer screenshot 1(a)). We are using the file.txt as an input to Linux shred command. The shred command will overwrite the data and data format is completely changed (refer screenshot 1(b)). It is very difficult to recover the shred file data.
Screenshot 1 (a)
Screenshot 1 (b)
Example #2 – Shred Command with “-n” option
The Linux shred command; we can define the number of times the shredding will happen on the file.
We can use the “-n” option with shred command.
shred -n 10 file.txt
As per the above command, we are using shred command on input file “file.txt”. We are using the “-n” option in shred command. It will overwrite the file ten times. The default value of overwriting is three.
Example #3 – Shred Command with “-u” option
In shred command, we are having the facility to overwrite the file but also we can delete the same shred file.
We can use the “-u” option with the shred command.
shred -u file.txt
In the Linux ecosystem, we need to delete the shred file in the same shred command. In the sample directory, we are having the input file i.e. file.txt. We are using the “-u” option in the shred command. You will observe that when we will use the “-u” option the file will shred and delete form the current location.
Example #4 – Shred Command with “-s” option
The shred command, we shred the number of lines as per the requirement. The remaining content or data or record is present as it is.
We need to use the “-s” option in shred command.
Note: The “-s” value should be in the number of bytes.
shred -s20 data.txt
In the sample directory, we have created a new input file “data.txt”. We are entering few records in it and the size of the file is 49 bytes (refer screenshot 2 (a)). As per the above command, we are shredding the input file form 0 bytes to 20 bytes. As per the “-s” option value, data will shred (refer screenshot 2 (b)).
Screenshot 2 (a)
Screenshot 2 (b)
Example #5 – Shred Command with “-v” option
In shred command, there is a facility to display the live operation performing by the shred command. To get the live execution messages status, we need to use the “-v” option with shred command.
Note: we can use the “-v” option with any shred command option. There is no restriction to use the “-v” option in the command.
shred -v -n 10 data.txt
In the shred environment, we are having the functionality to get the live query status. To get the shred command information, we need to use the “-v” option in the command. As per the below output, we are getting the live shred command update, where the command is, and what it is doing. Once the command execution will complete then the CLI curser comes into the original state.
We have seen the uncut concept of “Linux Shred Command” with the proper example, explanation, and command with different outputs. It can shred the file multiple times. Due to shred command, we are having the reliability that the data or file was completely overwritten or deleted and no one can recover the same data or file.
We hope that this EDUCBA information on “Linux Shred” was beneficial to you. You can view EDUCBA’s recommended articles for more information.