27th July 2024

How to Permanently Delete a File on Linux? Shred Command

You should be aware that the deletion used in Linux and other operating systems does not actually delete your files. We will explain the detailed description below.

  • If you are using a visual interface in the control system, you will definitely know the words Recycle Bin, Trash can. Right-click on the file in the desktop environment and select one of the DELETE-Send to Trash options.
Move to Trash
Move to Trash

 

  • Depending on your Operating System, there may also be a method to delete (Shift + Delete) the file without sending it to the Trash.

 

  • You can also delete from the command line with the rm command.

 

Note: Deletion is irreversible in the command line.

Whichever of the above-mentioned methods you use, your files are not physically deleted from the disk space where they were written. Only your operating system’s location catalogue, those addresses are empty information is encoded. Therefore it becomes writable. In fact, the data you think you deleted is still on your disk. Whenever new information is searched for to be written to disk, it is overwritten.

How can permanent deletion be done?

To do this, there is the shred command that comes preinstalled with Linux. The shred command does the deletion by going to the addresses on the disk itself. According to the rules you will write to the command parameters, it writes random data bits to the addresses where the file is located. Shreds the file, shuffles and overwrites 10-20-30 or more new random data, making it non-recyclable. The reason why this process is not used normally; An assumption is made that if you write too much data to the disc, the life of the disc will be shortened.

LEARN MORE  What is Metasploit? Update Error and Response

Example shred command

Let’s see how the shred command deletes a file.

root @ omer: ~ / Downloads # shred -vuf --iteration=30 DVWA-master.zip

In our example, there is a file named DVWA-master.zip, 10752 bytes long. For this file, -v (verbose), -u (remove), -f (force) parameters were given and the operation (iterations) was requested to be repeated 30 times. Here;

-v (verbose): It is required to show the process performed on the screen.

-u (remove): After the deletion, the file was requested to be divided and then deleted with the rm command. If the -u parameter is not used, the file name continues to appear in the system, even though the file is overwritten. Only the content cannot be read.

-f (force): With this parameter, it is allowed to change permissions even if the file is protected against deletion.

root@omer:~/Downloads# shred -vuf --iteration=30 DVWA-master.zip 
shred: DVWA-master.zip: pass 1/30 (random)...
shred: DVWA-master.zip: pass 2/30 (b6db6d)...
shred: DVWA-master.zip: pass 3/30 (dddddd)...
shred: DVWA-master.zip: pass 4/30 (777777)...
shred: DVWA-master.zip: pass 5/30 (ffffff)...
shred: DVWA-master.zip: pass 6/30 (000000)...
shred: DVWA-master.zip: pass 7/30 (aaaaaa)...
shred: DVWA-master.zip: pass 8/30 (c92492)...
shred: DVWA-master.zip: pass 9/30 (db6db6)...
shred: DVWA-master.zip: pass 10/30 (888888)...
shred: DVWA-master.zip: pass 11/30 (random)...
shred: DVWA-master.zip: pass 12/30 (555555)...
shred: DVWA-master.zip: pass 13/30 (bbbbbb)...
shred: DVWA-master.zip: pass 14/30 (6db6db)...
shred: DVWA-master.zip: pass 15/30 (124924)...
shred: DVWA-master.zip: pass 16/30 (111111)...
shred: DVWA-master.zip: pass 17/30 (999999)...
shred: DVWA-master.zip: pass 18/30 (333333)...
shred: DVWA-master.zip: pass 19/30 (444444)...
shred: DVWA-master.zip: pass 20/30 (800000)...
shred: DVWA-master.zip: pass 21/30 (random)...
shred: DVWA-master.zip: pass 22/30 (36db6d)...
shred: DVWA-master.zip: pass 23/30 (cccccc)...
shred: DVWA-master.zip: pass 24/30 (249249)...
shred: DVWA-master.zip: pass 25/30 (222222)...
shred: DVWA-master.zip: pass 26/30 (666666)...
shred: DVWA-master.zip: pass 27/30 (eeeeee)...
shred: DVWA-master.zip: pass 28/30 (492492)...
shred: DVWA-master.zip: pass 29/30 (924924)...
shred: DVWA-master.zip: pass 30/30 (random)...
shred: DVWA-master.zip: removing
shred: DVWA-master.zip: renamed to 000000000000000
shred: 000000000000000: renamed to 00000000000000
shred: 00000000000000: renamed to 0000000000000
shred: 0000000000000: renamed to 000000000000
shred: 000000000000: renamed to 00000000000
shred: 00000000000: renamed to 0000000000
shred: 0000000000: renamed to 000000000
shred: 000000000: renamed to 00000000
shred: 00000000: renamed to 0000000
shred: 0000000: renamed to 000000
shred: 000000: renamed to 00000
shred: 00000: renamed to 0000
shred: 0000: renamed to 000
shred: 000: renamed to 00
shred: 00: renamed to 0
shred: DVWA-master.zip: removed
root@omer:~/Downloads# 
shred command
shred command

 

LEARN MORE  Carbon Black EDR Sensor Access Error in 1 Hour and Solution

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *