SilverWav's Journal

The best is yet to come…

Posts Tagged ‘shred

Note: Shred All Files in a Directory

with 3 comments

Important – Could Delete Your System!

Make sure you use “Open in Terminal” or cd to the correct directory before running this command.

Or you will be sorry.

______________________________

Overwrite then Delete All Files in a Directory

find -type f -execdir shred -u -z '{}' \;

Explanation
The find command itself is used to find files matching a certain expression, on a certain path.

The the path argument is omitted, so find starts the search from the default current working directory.

The next argument to find, -type f, tells find to match only regular files (as we can’t shred directories).

The -execdir argument tells find to execute the command following the argument on each file matched (from that file’s parent directory).

We could alternatively have used the -exec argument, but -execdir is more secure because it changes directories before executing the command.

The remaining arguments are taken as the command to execute, until a terminating ‘;’ character is encountered.

We tell find to execute the shred command (with options) on each file matched.

The -u option to shred tells it to remove the file after shredding.

Find replaces the ‘{}’ string with the current file name being processed.

Note the braces are quoted to prevent expansion by the shell.

Finally, a semi-colon terminates the -execdir command.

The ; character is again escaped, this time with a ‘\’, to prevent expansion by the shell.

______________________________

Important – Could Kill Your Cat!

I don’t use this command, added for completeness.

If you do use it, ensure you have important data backed-up and a way of reinstalling your system.

I use Nautilus to delete directories as its safer :-)

______________________________

Delete a Tree of Directories.

Quote from opentux:
After executing the first command, all files in the directory tree have been securely shredded and removed, and all that is left is a tree of empty directories. Since the directories themselves contain no sensitive information (they are just a list of names and i-node numbers), they can be safely removed with rm.
I specified using the command
$>rm -rf *
to recursively (-r) remove all the directories without prompt (-f), since I knew all sensitive files to have been securely removed already. But alternatively if you wanted to make doubly sure you weren’t unsecurely removing any missed files, you could invoke rmdir on each remaining directory (from the bottom up).

link

Written by SilverWav

April 25, 2010 at 11:07 am

Posted in Notes

Tagged with , , , , ,