How do I untar a tar.gz file to multiple directories?
Hey everyone,
I am trying to find a way to untar a file.tar.gz in my home/noob directory into 15 different directories. where the tar.gz file is located: /home/noob where the 15 directories are located: /home/noob/Staging/ 1-15 folders Without having to extract the tarball individually, is there a simple way in one or two commands that can take the tarball and extract it to all 15 folders ? Please and thanks! |
I'm not sure I follow what your are trying to do and why. You could try something like this:
Code:
echo dir1 dir2 dir3 | xargs -n 1 cp file1 jdk |
Thank you.
I was trying to use find, xargs, and tar ... I am going to try it your way. I am just trying to automate some random tasks to be honest. I'm just trying to learn how to use different common commands and how to implement them together. |
That's great. Let us know how you make out. Be sure to post your solution to help others with a similar problem.
jdk |
Code:
find /home/noob/Staging/ -maxdepth 1 -type d -print0 | while read -d $'\0' dir; do echo tar -zxvf /home/noob/file.tar.gz -C "$dir"; done PS: The echo in red will give you a preview of of what the code will do without doing anything. Look at the output carefully and see if things look right. If it looks OK, run the code again without the echo part. |
FYI - initramfs's post can also be simplified by replacing the find, print, while, read with a simple for loop and an if to check for directories:
Code:
for dir in /home/noob/Staging/*; do if [[ -d $dir ]]; then echo tar -zxvf /home/noob/file.tar.gz -C "$dir"; fi; done |
Quote:
|
Quote:
Code:
reverse () { Code:
awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }' textfile Code:
sed '1!G;h;$!d' ${inputfile} Code:
tac textfile |
Quote:
|
No feedback from the OP, oh well... :/
|
Thanks for the feedback, everyone
Hey everyone.
Sorry for the late reply. At the time when I posted this, I was actually preparing for a job interview (yay!) that I actually got hired from, so the past 8 months has been a lot of hit-the-ground-running type of scenarios. I wanted to say thank you for all the help and contributions. I wish I still had the virtual machine I was using at the time so I could post the script and show it to you all, but it definitely used a lot of the methods you all mentioned on this post. Thanks again! |
on a desktop install of any major OS
r-click the tarbal and select "extract here" from the menu terminal tar -x tarbal.tar.gz or the ( tarbal.tgz ) |
An old solution (and a bit tacky, but I was impatient at the time):
Code:
... Code:
(cd $i; tar -xf <tarfile> . )& The other thing to note - don't do this for LOTS of diretories as it can tie up a server with large tarfiles. (I made that mistake from a client of a NFS server, and tied it up for about 15 minutes. Long enough for people to start running around to find out what was hanging...) |
All times are GMT -5. The time now is 05:35 PM. |