Deleting the trash with Shred

shred

When we delete a file from our hard drive (with the rm command, for example), the information contained in it remains on the hardware even though the operating system informs us that the file has been deleted.

This is applicable to the cleaning of data (history, etc.) that web browsers perform through the options in their menus. All this information is easily recoverable with programs like Testdisk o photorec.

This, which on some occasions can be a resource that is very useful to us, can on other occasions make it possible to recover information from our computer that we explicitly wanted to be completely eliminated. A frequent case is when we want to sell our computer and be sure that nobody will be able to recover any data from it.

For a safe deletion of files there is, among others, the command shred.

shred is a utility for secure file deletion that overwrites files with random characters and patterns that make the information contained in it become garbage.

The number of overwrite times is specified with the option n "number". Other options are -z to do one last override with zeros, -v to inform us of the process and -u to delete the file after it is overwritten.

It is a bit tedious to use the shred command for each file. Furthermore, it does not act on directories. To make its use more comfortable, we can proceed by sending all the information that we want to delete to the trash (including sensitive information) and, each time we want to use the following script:

#! / bin / bash path_to_trap = $ HOME '/. local / share / Trash / files' #Change the value of the internal Separator value_ifs = $ IFS IFS = $ (echo -en "\ n \ b") cd $ path_to_trap # First delete all files for f in $ (find. -Type "f") do let length__string_fragment = `expr length $ f`-1 file = $ path_to_string $ {f: 1: $ length__string_fragment} shred -n3 -v -z -u $ file echo $ file done # Remove directories for directory in $ (ls -a) do if [["$ directory"! = "." && "$ directory"! = ".."]] then rm -r $ directory fi done #Restore IFS values ​​IFS = $ value_ifs echo "End of deletion (click to continue)" read a # ------ -------------------------------------------------- --------

In Debian 6 and 7, the path to trash is the one indicated in the variable path_to_ trash. If it differs in other distros, you just have to change this in the script.

To leave the disk clean, we can create a directory where we can recover all the "hidden" data, then move it to the trash and then apply this script.

I hope you find it useful.


Leave a Comment

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

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   elav said

    Interesting! 🙂

  2.   xino93 said

    very useful, thanks.

    1.    danield during said

      I'm glad you find it useful

  3.   RAW-Basic said

    Great! .. ..thanks for sharing ..

    To bookmarks .. 😉

    1.    danield during said

      :;

  4.   Essau said

    better yet, much more powerful and you can also delete full directories: install secure-delete package, and command "srm file" makes the file disappear. And "srm -r directory" crushes the directory and everything in it.

    * 1 pass with 0xff
    * 5 random passes.
    * 27 passes with the special values ​​defined by Peter Gutmann.
    * renaming the file with a random value
    * truncated file

    1.    danield during said

      I didn't know him, Essaú, but he looks a lot better than shred. Thank you

  5.   BryanDG said

    Speaking of Shred I want to share with you a service menu that I made for KDE which will delete the selected files
    link to the code http://paste.desdelinux.net/4820

    I explain the part of exec = below:
    -mv% f% u: is to change the name of the file (s) for example from foto01.jpg to foto01.jpgtxt.jpg.mp4.rar.zip.mov.mov.ar (this is to give it a little more security when deleting)
    -shred -n 3 -z% u.txt -u: where -n 3 overwrites the renamed file 3 times with mv (% u) and -u is so that after overwriting the file it will permanently delete it (without going through the trash can).

    the path where the file should be is:
    /home/USUARIO/.kde/share/kde4/services/ (where USER is the name of your personal folder)

    the file extension is .desktop (I have shred.desktop for it)

    Well I wanted to share my code, they tell me anything :)