Jon Nelson on 10 May 2005 14:15:39 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Tutorials


Mark M. Hoffman said:
> Hi Jon:
>
> * Jon Nelson <quincy@linuxnotes.net> [2005-05-06 15:14:57 -0400]:
>> Sure it can and so can any other command with 'xargs':
>>
>>     $ find ../dir1/ | cpio -o --format=tar > test.tar
>>
>> would be:
>>
>>     $ find ../dir1/ | xargs tar cvf test.tar
>
> Ugh, no.  The xargs man page says:
>
> 	xargs reads arguments from the standard input, delimited
> 	by  blanks  (which can  be protected with double or single
> 	quotes or a backslash) or newlines, and executes the command
> 	(default is /bin/echo) one or more times with any initial-
> 	                       ^^^^^^^^^^^^^^^^^
> 	arguments followed by arguments read from standard input.
>
> If you use xargs with tar that way (on a big enough directory tree)
> you will end up missing files.

Mark,

If I understand your post correctly you feel that on a larger tree you
might encounter files with spaces in them.  Thus 'xargs' would only echo a
portion of the filename and you would not have that file in your archive.

That's why I mentioned '-print0' in my first post.  I believe this would
take care of the above:

    $ find ../dir1/ -print0 | xargs --null tar cvf test.tar

This is also mentioned in the "Advanced Bash-Scripting Guide" here:

    http://tldp.org/LDP/abs/html/special-chars.html#EX58

I don't think the '-r' option for 'tar' is necessary because the 'tar'
command is executed once, not for every argument.  Really, I guess '-r' or
'-c' would work.

Jon

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug