- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Why does tar not work?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 03:51 AM
тАО04-06-2004 03:51 AM
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?)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 03:57 AM
тАО04-06-2004 03:57 AM
Re: Why does tar not work?
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 03:57 AM
тАО04-06-2004 03:57 AM
Re: Why does tar not work?
or find /tmp | xargs tar -fcv tmp.tar
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 04:04 AM
тАО04-06-2004 04:04 AM
Re: Why does tar not work?
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 04:09 AM
тАО04-06-2004 04:09 AM
Re: Why does tar not work?
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 04:14 AM
тАО04-06-2004 04:14 AM
Re: Why does tar not work?
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 04:15 AM
тАО04-06-2004 04:15 AM
Re: Why does tar not work?
works for me here, provided I'm in the correct directory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 04:19 AM
тАО04-06-2004 04:19 AM
Re: Why does tar not work?
please, do following test:
% find dir | xargs tar cvf dirnam.tar
% find dir | wc
output??
% tar ft dirnam.tar | wc
output??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 04:24 AM
тАО04-06-2004 04:24 AM
Re: Why does tar not work?
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 04:26 AM
тАО04-06-2004 04:26 AM
Re: Why does tar not work?
79 633 6292
root@hp19rm4 [/tmp]
# find /home/mfstrong | wc
105 106 3789
hmm I see your point.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 04:42 AM
тАО04-06-2004 04:42 AM
Re: Why does tar not work?
in my opinion, there's no problem with the order of 'ft' or 'tf' or such things.
Marvin, Sanya,
anything new??
Patrick,
already at home? Really, no need to change to Linux?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 04:56 AM
тАО04-06-2004 04:56 AM
Re: Why does tar not work?
I think the problem is within the command sequence.
Xargs takes as many arguments as possible, and starts the tar command with all these arguments. This means that tar will be started multiple times, each time overwriting the previously made tarfile. Your tarfile probably only contains the last XX files.
Don't use xargs, just do
find .... | tar cvf tarfile.
JP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 04:56 AM
тАО04-06-2004 04:56 AM
Solutionfind dir | cpio -oc > output
my results:
# find scripts | wc
68 68 1528
root@hp19rm4 [/home/mfstrong]
# find scripts | cpio -oc > scripts.cpio
349 blocks
# cpio -ict < scripts.cpio | wc
349 blocks
68 68 1528
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 05:05 AM
тАО04-06-2004 05:05 AM
Re: Why does tar not work?
type args, type tar
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 05:10 AM
тАО04-06-2004 05:10 AM
Re: Why does tar not work?
The reason for this is that other arguments may require additional arguments. "b" immediately comes to mind.
I.E.
tar -cvbf 2048 -
To fix the problem, try a different approach.
tar -cvf myfiles.tar `find . -depth -print`
Notice the grave marks enclosing the find command. The grave marks tell the shell to execute the command enclosed to get it's arguments.
Regards,
Shannon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 05:30 AM
тАО04-06-2004 05:30 AM
Re: Why does tar not work?
"find tmp" is not compiant usage of the find command. This could produce an empty list, or pathing issues.
You do not state that an arcive is not made, just that the path is not reflected.
Is an archive made at all? if so what is the contents? There should be something in archive.
If you want absolute pathing in the file, then find needs to give an absolute path.
find /tmp -depth -print
makes the absolute path /tmp
find . -depth -print
makes the cwd the absolute path.
Another problem I noticed is that in your -exec example you do not give the path to tar, which is required for execution.
find /tmp -depth -exec /usr/bin/tar rf myfile.tar {} \;
Try not to be lazy with command arguments. While it may work under certain circumstances, it will not work in all cases.
Lastly, which tar are you using? and are you using a hybred find? It can make a difference if LD_LIBRARY_PATH needs to be adjusted.
Regards,
Shannon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 06:02 AM
тАО04-06-2004 06:02 AM
Re: Why does tar not work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 06:05 AM
тАО04-06-2004 06:05 AM
Re: Why does tar not work?
# cd /tmp
# find . -print > /dir/file_list
# tar -cvf file.tar $(cat /dir/file_list)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 06:06 AM
тАО04-06-2004 06:06 AM
Re: Why does tar not work?
I think I once experienced something similar, namely that the argument list for xargs was too long. I also seem to remember that xargs does only produce an error message if you use it with the -x option. Try testing your find commands like this:
# find
If it producces an error message like "xargs: arg list too long" we know what the problem is. If you can provoke that error message then try executing the above command without the "-x" option and without redirection.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-06-2004 06:38 AM
тАО04-06-2004 06:38 AM
Re: Why does tar not work?
by definition xargs cannot produce an argument list that is too long. Xargs will split the arguments such that the list is not too long, and the command (tar in this case) is called as few times as possible.
My point is: xarsg will call tar a few times because there are so many files. Only the files (arguments) in the last invocation of tar (by xargs) will be in the tar archive. All previously created archives are overwritten.
JP
P.S. Of course, if you add an argument manually, the arglist may become too long.
P.S. 2. The number of arguments in the list is smaller if filenames are longer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-07-2004 03:15 AM
тАО04-07-2004 03:15 AM
Re: Why does tar not work?
tar cf tmp.tar tmp
When you used the plain find command it listed both files and directories. That would cause tar to include multiple copies of files. When you use find to filter you also need to use a "-type f" filter so you only pass file names and not directory names.
The easy way to create a tar file with a really long list of names is to use pax instead of tar. It will write an archive format that tar can read. Pax will take a list of file names from stdin, so you can just pipe the output of find to it.
find tmp -type f | pax -w -f tmp.tar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-07-2004 04:36 AM
тАО04-07-2004 04:36 AM
Re: Why does tar not work?
touch dummy
tar cf tmp.dir dummy
find tmp -tpye f | xargs uvf tmp.dir
and you will find you have what you are looking for plus the dummy file.
Hope this helps.
-Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-07-2004 11:53 PM
тАО04-07-2004 11:53 PM
Re: Why does tar not work?
Special thanks to:
Marvin -- using cpio is a good work-around
Mike --
Your hint using '-type f' was the key. Also, using pax is really an easy way to create a tar file without running tar with a huge argument list, I didn't know that. Thank you.
Dave --
It's a good work-around, too. But, some little modifications on your solution must be done (using 'r' instead of 'u'; using '-n' option on xargs).