Taking from the last answer (by im3r3k) here: How do I recursively shred an entire directory tree?

I'm trying to get the find command to call a shell script as described.

So far I've tried:

find /home/shredtest/* -depth -exec /home/test.sh {}\;

where /home/shredtest is the directory whose contents I want to shred (but without removing /home/shredtest itself and where /home/test.sh is the script to run. I did chmod +x /home/test.sh.

The find command above returns:

find: -exec CMD must end by ';'

I've also tried:

find /home/shredtest/* -depth -exec /home/test.sh "{}"\;
find /home/shredtest/* -depth -exec /home/test.sh {}\;
find /home/shredtest/* -depth -exec sh /home/test.sh "{}"\;
find /home/shredtest/* -depth -exec sh \/home\/test.sh {}\;
find /home/shredtest/* -depth -exec sh \/home\/test.sh "{}"\;

all of which return the same error.


  1. Why is the -exec failing to see the semicolon? Obviously it's there and escaped so something else must be wrong. I just don't see it.
  2. Am I even going about this the right way or is there a better way to achieve this?

1 Answer 1


The ; has to be its own separate argument to find:

find /home/shredtest/ -depth -exec /home/test.sh "{}" \;

(note space between {} and \;). After -exec:

All following arguments to find are taken to be arguments to the command until an argument consisting of `;' is encountered.

(from man find). That is, the argument has to consist entirely of ; to stop the argument list.

You can also use `+' to pass many file arguments at once, which has to be its own argument too.

Note also that in find /home/shredtest/* the * is unnecessary: find will go through the directory contents itself, while * will be expanded by the shell (and occasionally may not lead to exactly the results you wanted).

  • Thank you Michael, will try those suggestions shortly. To address the * in find /home/shredtest/* I found, by running the find by itself, that without the trailing * the shredtest directory itself is included in the results. With the trailing * it's not. Is this not the right way or is there a better way to exclude shredtest from being shreded?
    – JoelAZ
    Jul 4, 2014 at 4:54
  • You can use -mindepth 1 to process only contents and not the command-line arguments themselves. Jul 4, 2014 at 4:59
  • Excellent, thank you Michael. Something as silly as a space derailed me for at least 45 minutes <doh>. And mindepth seems to work a treat. Thank you!
    – JoelAZ
    Jul 4, 2014 at 5:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .