Excluding a list of files from tar with spaces in filenames

Excluding a list of files from tar with spaces in filenames

Dotan Cohen dotancohen at gmail.com
Fri Feb 5 09:51:53 IST 2010


> Do
>
> tar -zcvf - *  --exclude-from $EXCLUDES > out.tar 2> tar.err
>
> to redirect stderr into a file.
>
> I just noticed that the way you specify the output tar file is not
> conventional. You tell it to use stdout then redirect it to a file
> using the shell, instead you can tell tar to open the file directly:
>
> tar -zcvf out.tar *  --exclude-from $EXCLUDES 2> tar.err
>
> (the 'f' in '-zcvf' tells tar to take the next command line argument
> as an output (or input, depends on the command) file name, '-' stands
> for stdout or stdin).
>

Actually, I am piping it through openssl to encrypt it first. That is
the reason for the non-conventional output. See here:

tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
dd of=$(hostname)-$(date +%Y%m%d).tbz

I tried appending " > OUTPUT" to the end in the hope that it would
capture the output to a variable with the name OUTPUT but that did not
work. So, How should I be doing that?


> Another error I noticed is that you provide the --exclude-from after
> the '*' which expands to input file names.
> Then you can redirect stderr to stdout in order to fetch it using back-ticks:
>
> tar_stdout_and_stderr=`tar -zcvf out.tar --exclude-from $EXCLUDES * 2>&1`
>

This is something that I cannot do because of the pipe to encryption.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il

Please CC me if you want to be sure that I read your message. I do not
read all list mail.



More information about the Linux-il mailing list