Reputation: 297
I'm copying bunch of .tar backups of user home directories to a new server and have the tarballs already copied from the old server to the new server.
For Example;
[[email protected] /home]# ls /home |grep tar
returns:
user1.tar
user2.tar
user3.tar
[etc]
But making things a little trickier, the tarballs were created from the root directory on the original server so a default extraction has 'home' in the default path e.g.;
[[email protected] /home]# tar -xvf user1.tar
extracts to a new home directory relative to where your running the command and places the extracted files at the path
/home/home/user1
The closest I believe I have come to what's required (with a few different variations);
[[email protected] /]# ls /home |grep tar |tar -xvf -
returns;
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
Now I realize there's a lot of workarounds for each of the different pieces, but if I'm going to grow up to be a super-cool sysadmin like my friends, I should probably know super-cool tricks like this.
Thanks!
Upvotes: 0
Views: 299
Reputation: 96266
tar
expects a tar file on stdin, not a list of filenames.
Process each file separately:
ls *.tar | xargs -n 1 tar xvf
or
for file in *.tar; do tar xvf $file; done
Upvotes: 1