Re: [SLUG] creating tar archive of filenames containing spaces

From: Eben King (eben01@verizon.net)
Date: Mon Apr 30 2007 - 16:49:52 EDT


>From: "Ian C. Blenke" <ian@blenke.com>
>Date: 2007/04/30 Mon PM 01:19:42 CDT

>Jonathon Conte wrote:
>
>> I want to write a script that uses ls and grep to
>> send a filtered list of files to tar to create an
>> archive. I'm getting hung up on filenames that
>> contain spaces. What looks wrong below?
>>
>> jconte@peregrine:~/Desktop/spaces$ ls
>> filename with spaces
>> jconte@peregrine:~/Desktop/spaces$ ls -Q
>> "filename with spaces"
>> jconte@peregrine:~/Desktop/spaces$ tar -cf ../test.tar $(ls -Q)
>
>
>You want something like find and xargs' null
>terminated delimiters:
>
> find . -type f -print0 | xargs -0 tar cf ../test.tar
>
>That'll do what you want to do.
>
>Simply put, find can output null terminated entries
>that can be fed to xargs as null terminated input
>entries which xargs then passes to the command in
>question.

I hope "find" doesn't spit out more filenames than
can go in "tar"'s argument list, because then xargs
will run tar again and it'll overwrite the existing
archive with the next batch. IIRC tar has an option
like "take names from filename" (-T?). Might "find
... | tar ... -T -" do what you want? Sorry if I'm
off base; my Linux box is down for a few days.

>You could also just tar up the entire directory:
>
> tar cf ../test.tar .
>
>Another option is to temporarily redefine IFS.

"/" can't occur in filenames.

-- 
-eben    QebWenE01R@vTerYizUonI.nOetP    royalty.mine.nu:81
TAURUS:  You will never find true happiness - what you gonna
do, cry about it?  The stars predict tomorrow you'll wake up,
do a bunch of stuff and then go back to sleep.  -- Weird Al

----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 16:14:52 EDT