1753637 Members
5763 Online
108798 Solutions
New Discussion юеВ

Why does tar not work?

 
SOLVED
Go to solution
Thomas Schler_1
Trusted Contributor

Why does tar not work?

Hi,

I need to create a tar archive using a combination of find, xargs, and tar. E.g.

find tmp | xargs tar fcv tmp.tar

(Assume some more options of find for filtering purposes.)

find produces an output of several hundred paths. All these files shall be put into one tar archive "tmp.tar". But this does not work. Although, I do not get an error message, the resulting tar archive never reflects the paths delivered by the find process.

I tried some other variants:

% tar fc tmp.tar `find tmp`

% tar fc tmp.tar any_file
% find tmp | xargs -n 10 tar fr tmp.tar

% tar fc tmp.tar any_file
% find tmp -exec tar fr tmp.tar {} \;

Nothing works. What is going wrong? What is the solution?

(Is it time to change from HP-UX 11.00 to Linux?)
no users -- no problems
22 REPLIES 22
Patrick Wallek
Honored Contributor

Re: Why does tar not work?

No, no need to change to Linux. You just need to get your command line options in the correct order.

Your 'f' option should immediately preceed the name of the file you are taring t.

# tar -cvf tmp.tar filenames

So in your examples:

# find tmp | xargs tar cvf tmp.tar -

Note the '-' at the end of the tar command as well. That tells tar to read the file names from standard input.
RAC_1
Honored Contributor

Re: Why does tar not work?

Is it find tmp | xargs tar fcv tmp.tar
or find /tmp | xargs tar -fcv tmp.tar

Anil
There is no substitute to HARDWORK
Sanjay_6
Honored Contributor

Re: Why does tar not work?

Hi,

the command works for me. I just ran the command that thomas has mentioned and got a tar file. What is the error you are getting. Hope you are not running out on filesystem space.

Hope this helps.

Regds
Thomas Schler_1
Trusted Contributor

Re: Why does tar not work?

Patrick,

unfortunately, there's no effect using '-' or using it not. Again, no error message, but:

% find tmp | xargs tar cvf tmp.tar -
% find tmp | wc
336 337 8656
% tar ft tmp.tar | wc
35 35 675

(Using xargs, '-' should be obsolete.)

Something is going wrong here. I assume, it has something to do with LINE_MAX, see xargs(1) and limits(5).

But, what is the work-around?
no users -- no problems
Thomas Schler_1
Trusted Contributor

Re: Why does tar not work?

Sanjay,

thank you for your test; no, file space is ok.

Please, see my answer to Patrick. Would you, please, again do the test with some hundreds of files, and, say about, 50 MB?
no users -- no problems
Marvin Strong
Honored Contributor

Re: Why does tar not work?

#find dir | xargs tar cvf dirnam.tar -

works for me here, provided I'm in the correct directory.

Thomas Schler_1
Trusted Contributor

Re: Why does tar not work?

Marvin,

please, do following test:

% find dir | xargs tar cvf dirnam.tar
% find dir | wc
output??

% tar ft dirnam.tar | wc
output??
no users -- no problems
Jason W. Neiss
Valued Contributor

Re: Why does tar not work?

> % tar ft dirnam.tar | wc

Again, the 'f' (file) option should come right before the filename:

% tar tf dirnam.tar | wc

Looks to me like this is consistently your issue...

Jason

Marvin Strong
Honored Contributor

Re: Why does tar not work?

# tar tvf mfstrong.home.tar | wc
79 633 6292
root@hp19rm4 [/tmp]
# find /home/mfstrong | wc
105 106 3789

hmm I see your point.