- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to overwrite a file to hide file contents, and make original contents unrecoverable in Linux?
To overwrite and file contents in the Linux system, we use the shred command using the terminal.
shred – The shred command is used to securely delete files and devices. This command overwrites a file to hide file contents, and optionally delete the file so that it is very difficult to recover the file for any software in the Linux/Unix system.
As usual, to remove files from the system, we use the rm command using the terminal. After removal files through the rm command, it may be recoverable using the software whereas after removing files through the shred command files are unrecoverable because the shred command overwrites the files three times with multiple patterns.
The general syntax of the shred command is as follows −
shred [OPTION]... FILE...
Brief description of option available in the shred command.
|Sr.No.||Option & Description|
Change the permissions to allow writing
Overwrite contents of the file N times instead of the default
Get random bytes from another file
Shred this many bytes
Remove file after overwriting
Just like -u option but give control how to delete file
Show what is happening
Overwrite file with zeros to hide shredding
Display this help and exit
Output version information and exit
Overwrite the contents of the file and make it unrecoverable in the Linux system.
To overwrite the contents of the file and make it unrecoverable, we use the shred command in the Linux/Unix system using the terminal as shown below.
$ shred file.txt
After executing this command, the file ‘file.txt’ is unrecoverable.
Overwrite the contents of the file and print what is being done in the Linux system.
To overwrite the contents of the file and print what is being done, we use --verbose option with the shred command in the Linux/Unix system using the terminal as shown in below.
vikash@tutorialspoint:~/shadow$ shred --verbose file.txt shred: file.txt: pass 1/3 (random)... shred: file.txt: pass 2/3 (random)... shred: file.txt: pass 3/3 (random)...
Overwrite only specific byte of the file in the Linux system.
To overwrite only specific byte of the file, we use -s option with the shred command in the Linux/Unix system as shown below.
vikash@tutorialspoint:~/shadow$ cat file.txt Hey, welcome to tutorialspoint... vikash@tutorialspoint:~/shadow$ shred -s 2 file.txt vikash@tutorialspoint:~/shadow$ cat file.txt y, welcome to tutorialspoint...
Display the help of the shred command and exit.
To check more information about the shred command, we use the –help option with the shred command in the Linux system as shown below.
$ shred --help
Conclusion – In this article, we learned to overwrite a file to hide its contents and optionally delete it using the shred command with available options and suitable examples. The rm command also used toremove the file in the Linux system.
- How to format contents of a text file in the Linux system?
- Print contents of a file in C
- Display Command Output or File Contents in Column Format in Linux
- How to read contents of a file using Scanner class?
- Golang Program to Read the Contents of a File
- How to delete all the file contents using PowerShell?
- C program to copy the contents of one file to another file?
- How to write contents of a file to byte array in Java?
- How to read the contents of a JSON file using Java?
- Java Program to Create String from Contents of a File
- How to store the contents of arrays in a file using Java?
- Java Program to Convert contents of a file to byte array and Vice-Versa
- C Program for copying the contents of one file into another file
- C# Program to read contents of a file into a string at once
- Merge contents of two files into a third file using C