- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Extracting from multiple tar files: Oneliner wante...
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
Forums
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
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
тАО09-23-2008 03:00 AM
тАО09-23-2008 03:00 AM
I'm extracting files from multiple tar files. This for-loop works:
$ for xx in `ls -1`; do tar xvf $xx; done
but why doesn't this little thing work?
$ ls -1 |awk '{print $1}' | tar xvf -
Tar gives no error message, but no extracting gets done. Puzzling...
Any pointers or comments?
Regards,
Runar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-23-2008 05:25 AM
тАО09-23-2008 05:25 AM
Re: Extracting from multiple tar files: Oneliner wanted
cat test.tar | tar tvf -
ls test.tar | tar tvf -
You are trying to do the second one, that won't ever work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-23-2008 08:51 PM
тАО09-23-2008 08:51 PM
Re: Extracting from multiple tar files: Oneliner wanted
Try below shell code for extracting many files.
tar_files=`ls *.tar 2>/dev/null`
if [ -n "$tar_files" ]
then
for i in $tar_files
do
tar -zxvf $i 2>&1
done
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-23-2008 11:08 PM
тАО09-23-2008 11:08 PM
Re: Extracting from multiple tar files: Oneliner wanted
I'm curious about your reply. I believed tar wanted a one-by-one list of file names as input. But, what you are saying is that I'm really supposed to supply the content of the tar files?
If I have two tar files FILE1.tar and FILE2.tar, Then this (below) should work, but it doesn't. Tar only extracts the first tar file. How come?
$ ls
FILE1.tar FILE2.tar
$ tar tvf FILE1.tar
-rw-r--r-- runar/wheel 401021 2008-02-27 08:42:06 typescript
-rw-r--r-- runar/wheel 0 2008-02-27 12:26:14 typescript1
-rw-r--r-- runar/wheel 0 2008-02-27 12:26:14 typescript10
-rw-r--r-- runar/wheel 0 2008-02-27 12:26:14 typescript2
-rw-r--r-- runar/wheel 0 2008-02-27 12:26:14 typescript3
-rw-r--r-- runar/wheel 0 2008-02-27 12:26:14 typescript4
-rw-r--r-- runar/wheel 0 2008-02-27 12:26:14 typescript5
-rw-r--r-- runar/wheel 0 2008-02-27 12:26:14 typescript6
-rw-r--r-- runar/wheel 0 2008-02-27 12:26:14 typescript7
-rw-r--r-- runar/wheel 0 2008-02-27 12:26:14 typescript8
-rw-r--r-- runar/wheel 0 2008-02-27 12:26:14 typescript9
$ tar tvf FILE2.tar
-rw-r--r-- runar/wheel 144244 2008-02-27 12:39:21 find_xargs.log
-rw-r--r-- runar/wheel 0 2008-02-27 12:28:15 fred.foo
$ cat *.tar | tar xvf -
typescript
typescript1
typescript10
typescript2
typescript3
typescript4
typescript5
typescript6
typescript7
typescript8
typescript9
runar@MMtux:~/tmp$ ls
FILE1.tar typescript typescript10 typescript3 typescript5 typescript7 typescript9
FILE2.tar typescript1 typescript2 typescript4 typescript6 typescript8
Troy,
Thanx for the script.
Regards,
Runar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-24-2008 06:23 AM
тАО09-24-2008 06:23 AM
Solutioncat tar1.tar > tar3.tar
cat tar2.tar >> tar3.tar
At that point, you should have tar1 and tar2 in the tar3.tar file. But the problem is that tar1.tar also stored it's end of tar archive mark in the file, so, you won't be able to continue above the end of the tar1 content even in the tar3 file.
As you cannot "forward" a mark in the tarfile as in a tape (mt fsf), probably you won't be able to read the second tar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-24-2008 04:41 PM
тАО09-24-2008 04:41 PM
Re: Extracting from multiple tar files: Oneliner wanted
from tape:
while [ $? == 0 ] ; do tar xvf /dev/nst0
for a directory on disk
for x in $(ls
I also pipe the output to a file for review if needed.
Ray
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-26-2008 12:16 AM
тАО09-26-2008 12:16 AM
Re: Extracting from multiple tar files: Oneliner wanted
Thanx
Runar