SilverWav's Journal

The best is yet to come…

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 '{}' \;

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).



Written by SilverWav

April 25, 2010 at 11:07 am

Posted in Notes

Tagged with , , , , ,

3 Responses

Subscribe to comments with RSS.

  1. “I use Nautilus to delete directories as its safer”

    Depends on what you mean by safer.

    The purpose of shred is not just to delete but to *securely* delete files. Deleting files from nautilus won’t achieve this.


    June 20, 2010 at 11:54 pm

    • Correct. But I said folders not files. You cant use shred on folders just files.

      My quote referred to the safety (or not) of using rm -rf * as opposed to Nautilus for deleting the remaining empty folders.

      I recommend shred for securely deleting the files then using Nautilus to delete and folders.


      June 21, 2010 at 12:10 am

  2. Could you also use xargs? As in,

    find ./ -name “*” | xargs shred -u


    Edward Tisdale

    October 9, 2013 at 2:30 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: