35

I want a command to shred completely the contents of a folder/directory (which may be inside folders/directories). Also please explain the command.

Peachy
  • 7,235
  • 10
  • 40
  • 47
Ashu
  • 9,642

8 Answers8

37
  1. Install the package secure-delete.
  2. Use the command srm -r pathname to remove your folder and files.

The default settings are for 38 (!!!) passes of overwrites which is extreme overkill imho (see more info about this here).

For my usage, I only want a single pass of random data so I use srm -rfll pathname.

If you want to create a right-click option in the GUI for files and folders, use gnome-actions to call a script like this:

#!/bin/bash
if dialog=`zenity --window-icon=warning --question --title="Secure Delete" --no-wrap --text="Are you sure you want to securely delete:\n\n     $1\n\nand any other files and folders selected? File data will be overwritten and cannot be recovered."` 
then /usr/bin/srm -fllrv "$@"| zenity --progress --pulsate --text="File deletion in progress..." --title="Secure Delete" --auto-close
fi 

If you want more paranoid settings be sure to modify the above script.

luk3yx
  • 401
Veazer
  • 1,471
15

For files not directories, here's a more simple way instead of -exec shred -u {} \; type of way:

cd to your directory.

then

find . -type f -print0 | xargs -0 shred -fuzv -n 48

this does 48 passes recursively to the current directory you cd'ed into.

Hope this helps some.

Francisco
  • 263
  • 2
  • 6
3

sudo apt install wipe

$ wipe -rfi dir/*

where the flags used: -r – tells wipe to recurse into subdirectories -f – enables forced deletion and disable confirmation query -i – shows progress of deletion process

Demon
  • 838
3

Shred works only on files. You need to shred the files in the dir/subdirs first and then remove the directories. try

find [PATH_TO_DIR] 

and make sure you only see the files you want to delete

find [PATH_TO_DIR] -exec shred -u {} \;

then remove the dirs with

rm -rf [PATH_TO_DIR]
David Oneill
  • 12,614
Ruediger
  • 2,202
1

You probably want to use something similar to this:

find dir -type f -exec shred -fuz {} +
rm -rf dir

First command finds only files and passes them to shred (as many at once as possible - no need to start a new shred process for every file like \; does). Finally, remove the directories too.

user1338062
  • 1,018
0

I have inserted the following bash script for this purpose in my .bashrc

function rm2 {

  for var in $@
  do
  if [ -d $var ]
  then
     nohup $( /usr/bin/find "$var" -type f -exec  shred -n 2 -u -z -x {} \;;/bin/rm -rf "$var" ) & 
  else
    nohup /usr/bin/shred -x -n 2 -u -z "$var" & 
  fi
done
exit
}
0

If you want to do this from Nautilus (aka 'Files' app), then you could use the nautilus-wipe package.

  • sudo apt-get install nautilus-wipe

Once installed, there will be two new options when you right-click on a folder: Wipe and Wipe available disk space. Choosing Wipe on the folder will give further options (e.g. number of passes, fast mode, last pass with zeros).

Jaydin
  • 1,571
-1

When I need to shred multiple files or an entire directory I simply use shred -vzn 20 ./shredme/*.* for example, which overwrites all files with any file extension in the "shredme" folder. Then you can use the standard rm -rf ./shredme command to remove the folder itself (or just right click and delete the folder) as all the data has been overwritten 20 times for this example.

I did a quick example of this with a bunch of duplicate images as an example.

Terminal screenshot

Oli
  • 299,380