I have a find command that I exec to shred and it works great; however, I need to capture the output of this and pass to a variable or a file. I have tried so many iterations of the below commands, but cant seem to get it to work. I also have tried for loops. It always will display to my terminal as it goes through the shred process, but never writes to a file or variable. I would prefer a variable but will take anything at this point. Please see my examples below:

Original find command:

find /burncd/working -type f -exec shred -v -n7 -z --remove {} \; 

Latest try at a command to pass to a file (from StackExchange):

find /burncd/working/* -type f -exec bash -c 'shred -v -n7 -z --remove "$1" /tmp/find.out' $0 {} \;

I would appreciate any help you could give.


1 Answer 1


shred seems to output the progress status to stderr and not stdout, so you need to use the 2> or 2>> for redirecting that output.

Something like this would redirect the stderr of both find and shred:

find . -type f -exec shred -n1 -v {} + 2> /tmp/shred.out

And this would redirect just the stderr of shred:

> ../shred.out
find . -type f -exec sh -c 'shred -n1 -v "$@" 2>> /tmp/shred.out' find-sh {} + 

(The shell that find starts gets find-sh and the filenames as arguments, find-sh goes to $0, the filenames to $1, $2..., all of which "$@" expands as distinct words. The string that goes to $0 can be arbitrary, but it helps to be somewhat descriptive since it may be used in error messages.)

Also you could do something like this to get the output of find and shred to both the file and the terminal:

find . -type f -exec shred -n1 -v {} + 2>&1 | tee /tmp/shred.out

(Similarly find .. -exec sh -c 'shred ... 2>&1 | tee /tmp/shred.out' find-sh {} + should work to only put the output of shred through tee. Though back-to-back outputs from find and shred could get mixed in the wrong order if you do that.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.