Excluding a list of files from tar with spaces in filenames

Excluding a list of files from tar with spaces in filenames

Shlomi Fish shlomif at iglu.org.il
Thu Feb 4 21:43:16 IST 2010


On Thursday 04 Feb 2010 21:12:54 Dotan Cohen wrote:
> I hope there is a bash guru out there today. I need to script a backup
> plan which has a list of directories that should not be backed up.
> Some of these directories have spaces in their filenames. The
> following script works so long as there are no directories with spaces
> in DONT_COPY, however, I cannot figure out what to do to get it to
> work _with_ spaces in filenames:
> 
> #!/bin/bash
> 
> DONT_COPY="
> .adobe/
> File with Spaces
> .bin/google-earth
> Yet Another Annoying Filename
> "

Use a bash array/list/whatever-it's-called:

DONT_COPY=(.adobe/ "File With Spaces" .bin/google-earth "Yet Another Annoying 
Filename")

> 
> DONT_COPY_LIST=""
> for pattern in $DONT_COPY ; do DONT_COPY_LIST="$DONT_COPY_LIST
> --exclude=$pattern "; done

Here you should do:

<<<
DONT_COPY_LIST+="--exclude='$pattern' "
>>>

Or maybe use an array again.

> tar -zcvf - * $DONT_COPY_LIST
> 
> 
> Any ideas? Thanks!

You can also use Perl/Python/Ruby/etc. which are more robust for such stuff.

Regards,

	Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
What does "Zionism" mean? - http://shlom.in/def-zionism

Deletionists delete Wikipedia articles that they consider lame.
Chuck Norris deletes deletionists whom he considers lame.

Please reply to list if it's a mailing list post - http://shlom.in/reply .



More information about the Linux-il mailing list