- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- find files and tar them
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
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
тАО08-11-2009 02:19 PM
тАО08-11-2009 02:19 PM
How do i use find and tar command together ?
I just want to find some files and tar the output in a tar file.
Thanks,
Shiv
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2009 02:29 PM
тАО08-11-2009 02:29 PM
SolutionIf we assume HP-UX (since it is in that community that you ask), then I'd do something like this:
# FILES=$(find /path -xdev -type f -mtime +7)
# tar -cvf /tmp/myarchive ${FILES}
...or whatever your specification is for collecting the files ...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2009 08:26 PM
тАО08-11-2009 08:26 PM
Re: find files and tar them
> # tar -cvf /tmp/myarchive ${FILES}
And what is the command-line length limit
these days?
And then there are the potential problems in
the funny-file-name class:
dyi # ls -l gtt
total 0
-rw-r--r-- 1 root sys 0 Aug 11 12:59 a a
dyi # FILES=$( find gtt -type f )
dyi # echo ${FILES}
gtt/a a
dyi # tar cvf gtt.tar ${FILES}
tar: cannot stat gtt/a. Not dumped.
tar: cannot stat a. Not dumped.
GNU "tar" has a "--files-from=file-name"
("-T file-name") option which can be helpful
in cases where "${FILES}" would cause
problems. "--files-from=-" or "-T -" works
to get the file names from stdin, so a "find"
pipeline can feed in the file names. For
example:
dyi # find gtt -type f | gtar cfv gtt.tar -T -
gtt/a a
dyi # tar tfv gtt.tar
rw-r--r-- 0/3 0 Aug 11 12:59 2009 gtt/a a
dyi # uname -a
HP-UX dyi B.11.31 U ia64 4235313755 unlimited-user license
dyi # gtar --version
tar (GNU tar) 1.18
[...]
For a variety of reasons, it's often a bad
idea to use file-name wild cards (like "*"),
or equivalent constructs, in a command line.
One of the best reasons to use "find" is to
avoid problems like this, but sloppy use of
"find" can effectively demolish many of its
advantages.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2009 09:05 PM
тАО08-11-2009 09:05 PM
Re: find files and tar them
For example:
find ./ -name "..." -exec tar cvf {} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-12-2009 02:53 AM
тАО08-12-2009 02:53 AM
Re: find files and tar them
If you have a trivial number of files, you can use JRF's example. Or you use Steven's gtar example.
Otherwise you don't use tar. Instead you use pax(1):
find /path -xdev -type f -mtime +7 | pax -v -w -f /tmp/myarchive
You can use pax or tar to restore.
>Andrey: You can try -exec option of find command also.
There are lots of reasons this won't work, don't even try.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-12-2009 03:55 AM
тАО08-12-2009 03:55 AM
Re: find files and tar them
> don't even try.
Or, if you're the fellow who made the
suggestion, then try it _before_ posting it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-12-2009 03:59 AM
тАО08-12-2009 03:59 AM
Re: find files and tar them
> Steven: And what is the command-line length limit these days?
Far larger than the days of HP-UX 10.20 and prior:
# getconf ARG_MAX
2048000
That said, on an "un-enhanced" HP-UX system (i.e. without some of the really nice GNU tools), I agree with Dennis --- 'pax' is probably the better choice. Oh, and your point about nasty files with embedded spaces is well taken, of course.
Regards!
...JRF...