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

From: Ian C. Blenke (ian@blenke.com)
Date: Mon Apr 30 2007 - 14:19:42 EDT


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.

You could also just tar up the entire directory:

    tar cf ../test.tar .

Another option is to temporarily redefine IFS.

Quoting and dequoting is such a pain.

 - Ian C. Blenke <icblenke@nks.net>

-----------------------------------------------------------------------
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