⬆️ ⬇️

Shred and permanent file deletion

In this article I will tell you how you can once and for all delete files from your hard disk in Ubuntu OS. So, meet - the shred team.



Not everyone knows that by deleting a file with rm or through a file manager, the file itself is not deleted, but its index is overwritten and the space that occupied the file is recorded by the system as free to write. The file, as you already understood, remained in its place and it would not be difficult to restore it from there. He will lie there until you replace other information in his place.



Shred with random numbers fills the space occupied by the file. And even, having restored your deleted file, it will be impossible to read it. By default, shred does not delete the file, the --remove (-u) parameter is used for this.



shred -u /path/to/file



The shred contains a 25-cycle loop, that is, the program will overwrite the file with random content 25 times. To change this value, for example, to 35-fold:

')

shred -u -n 35 /path/to/file






If your paranoia has reached an even greater level, then the following tips will suit you.



To hide the information that you cleaned the file, use the -z parameter, which adds zeros to the end of the file - this will make the file look different from the encrypted one. If you are interested in observing the rewriting process, the -v (verbose) parameter is used to display the progress information in detail.



shred -u -z /path/to/file



If you want to delete several files at once, then specify them in this format:



shred -u -z -n 30 /path/to/file1 /path/to/file2 /path/to/file3

or you can use a mask:

shred -u -z -n *.txt



Shred can also delete the contents of the entire hard disk with the command

shred /dev/sda



Naturally, the execution time of operations directly depends on the file size and write speed.



The only drawback I found was that shred can't delete directories. This is where the wipe utility comes to our rescue:

wipe -rf /path/to/catalog



For more information, use man shred and man wipe .






If you have already deleted the files and do not want to restore them and then delete them “correctly” because of their large size, then one thing remains - to overwrite with other information. Information that does not carry anything. This is where the dd utility comes to the rescue.



dd if=/dev/zero of=/path/to/file.trash bs=1M count=1024

where the count value is the file size you need. 1024 = 1GB, 2048 = 2GB, etc.



After creating the file, delete it already by shred.

Source: https://habr.com/ru/post/149104/



All Articles