
- Kali Linux Tutorial
- Kali Linux - Home
- Installation & Configuration
- Information Gathering Tools
- Vulnerability Analyses Tools
- Kali Linux - Wireless Attacks
- Website Penetration Testing
- Kali Linux - Exploitation Tools
- Kali Linux - Forensics Tools
- Kali Linux - Social Engineering
- Kali Linux - Stressing Tools
- Kali Linux - Sniffing & Spoofing
- Kali Linux - Password Cracking Tools
- Kali Linux - Maintaining Access
- Kali Linux - Reverse Engineering
- Kali Linux - Reporting Tools
- Kali Linux Useful Resources
- Kali Linux - Quick Guide
- Kali Linux - Useful Resources
- Kali Linux - Discussion
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.
Syntax
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 |
---|---|
1 | -f, --force Change the permissions to allow writing |
2 | -n, --iteration=N Overwrite contents of the file N times instead of the default |
3 | --random-source=FILE Get random bytes from another file |
4 | -s, --size=N Shred this many bytes |
5 | -u Remove file after overwriting |
6 | --remove[=HOW] Just like -u option but give control how to delete file |
7 | -v Show what is happening |
8 | -z, --zero Overwrite file with zeros to hide shredding |
9 | --help Display this help and exit |
10 | --version Output version information and exit |
Example
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.
Example
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)...
Example
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.
- Related Articles
- How to format contents of a text file in the Linux system?
- How to Append Contents of Multiple Files Into One File on Linux?
- Display Command Output or File Contents in Column Format in Linux
- How to read contents of a file using Scanner class?
- Print contents of a file in C
- How to delete all the file contents using PowerShell?
- How to write contents of a file to byte array in Java?
- C program to copy the contents of one file to another file?
- Golang Program to Read the Contents of a File
- How to read the contents of a JSON file using Java?
- How to store the contents of arrays in a file using Java?
- Java Program to Create String from Contents of a File
- Golang program to create string from contents of a file
- 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
