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

Re: A silly question about tar



On Sat, Mar 17, 2007 at 01:23:02PM +0000, Tyler Smith wrote:
> On 2007-03-17, Douglas Allan Tutty <dtutty@porchlight.ca> wrote:
> >
 
> I have, and unfortunately it doesn't work. The result is the same as
> the original problem with the regular * expansion:
> 
> tyler:tar-> find ./ -name '*.tar.gz' | xargs echo
> ../one.tar.gz ./three.tar.gz ./two.tar.gz
> 
> replace echo with tar, and you see that tar is going to try and
> extract the second and third archives from within the first archive,
> which fails. I think you have to use some sort of loop, as other
> posters have suggested.
> 

Make a directory to work in and change to it.

Make three files with the following contents:
	file:		Contents (one line with a trailing newline):
	first.txt	first file
	second.txt	second file
	third.txt	third file

---

	$ ls -1 *.txt
	first.txt
	second.txt
	third.txt

	$ls -1 *.txt | xargs
	first.txt second.txt third.txt

	# which makes sense since if you say:
	$ echo first.txt
	first.txt

---
But what you want as a test is a command that process its input as a
file not a string (like echo).  Try cat:

	$ cat first.txt
	first file

	$ls -1 | xargs -L 1 cat
	first file
	
	second file
	
	third file

	$
--
However, since cat will process more than one file, we don't know what
really is happening but the -L 1 should make xargs make a new comand
line for each line of input which is why I used ls -1.

I tarred this test directory up into a tarball called first.tar.gz.

I created a similar second set of files fourth.txt fifth.txt sixth.txt
into second.tar.gz

I created a third set seventh.txt eighth.txt and ninth.txt into
third.tar.gz

I then removed all the files so my test directory only had the three
tarballs.  Within that directory I issued:

	$ls -1 | xargs -L 1 tar -xf

and ended up with a test subdirectory containing all nine files.

Doug.




Reply to: