Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

create tarball reading file paths from stdin?

Hello,

I thought for sure I had done this before. I'd like to create an archive of certain file types using the output of find. But I can't convince tar to read these file paths from stdin. Here's what I've tried so far:
<pre style="overflow: auto;font-size:small; font-family: Monaco, 'Courier New', Courier, monospace; color: #222; background: #ddd; padding: .3em .8em .3em .8em; font-size: 10px;">ls test? | tar cvf test.tar -f -
tar: Multiple archive files requires `-M' option
Try `tar --help' for more information.

ls test? | tar cvf test.tar --file -
tar: Multiple archive files requires `-M' option
Try `tar --help' for more information.

ls test? | tar cvf test.tar -F -
tar: Cowardly refusing to create an empty archive
Try `tar --help' for more information.

ls test? | tar cvf test.tar -
tar: -: Cannot stat: (null)
tar: Error exit delayed from previous errors</pre>
Am I missing something obvious? Thanks for any tips.

--
Cole

15 PB Mac OS X (10.3.9)

15 PB, Mac OS X (10.3.9)

Posted on Mar 6, 2007 9:01 AM

Reply
9 replies

Mar 6, 2007 3:41 PM in response to Caleb Mattoon

weird. that doesn't work for me, either.

i tried this, which almost worked:

ls sandbox | xargs tar cvf -C ~/sandbox sandbox.tar

there's a bunch of data in that folder, and i got stat errors like the following:

tar: roundup-1.3.3: Cannot stat: No such file or directory

that directory does exist in ~/sandbox, though. when i first tried piping the file list to tar, it seems tar won't process the listing without the full path to the file. the -C changes directory to the intended one before running through the enclosed files.

hmmm…

Mar 6, 2007 5:18 PM in response to Cole Tierney

Thanks for the replies.

I definitely remember doing something like this and I very rarely use xargs (though I probably should!). In fact I found the script that I wrote that crawls a website printing the paths of text files to stdout. I remember piping this to tar, but just can't remember how. But I'm quite sure it wasn't via xargs.

I used ls as a bare bones test case.

--
Cole

Mar 18, 2007 7:44 PM in response to Cole Tierney

Hi Cole,
I think I know what you were thinking of. A while back I copied several commands that used tar in a pipe and I could have sworn they were yours. Here are some examples:

tar -cvf - source_dir | tar -C dest_dir -xvf -
tar -C <dir1> -chf - <dir2> | tar -C <dir3> --suffix=.orig -xf -
tar -C dir1 -cf - dir2 | ssh -l <ruser> -e none <rhost> "tar -C destdir -xf -"
ssh -l <ruser> -e none <rhost> "tar -C dir1 -cf - dir2" | tar -C destdir -xf -
cat file.tar | ssh -l <ruser> -e none <rhost> "tar -C <dir to untar to> -xf -"

If these aren't your commands, they at least look a little like what you posted. However as you can see, these commands use the command line to pipe the actual data and not a list of files. I'm guessing that you were thinking about commands like these but were forgetting about the piping of data.
--
Gary
~~~~
A sadist is a masochist who follows the Golden Rule.

create tarball reading file paths from stdin?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.