Mark M. Hoffman on 10 May 2005 16:26:04 -0000


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

Re: [PLUG] Tutorials


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

> Mark M. Hoffman said:
> > 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.

* Jon Nelson <quincy@linuxnotes.net> [2005-05-10 10:16:35 -0400]:
> 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.

No, that's not it.  I'll try to explain better...

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

This is what you missed.  If you use xargs with tar that way, on a big
enough directory tree, xargs *will* execute tar *more* than once.  The
section of the man page I quoted says so quite clearly.  The suggestion
(not mine) to use -r therefore makes good sense (although, maybe delete
the target tarfile first depending on the task).

Regards,

-- 
Mark M. Hoffman
mhoffman@lightlink.com

___________________________________________________________________________
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