?
Solved

Untar'ing and changing directory

Posted on 2009-05-11
5
Medium Priority
?
342 Views
Last Modified: 2013-12-16
Ok, this is a dumb problem I know.  However it can be solved, sweet.  I have a tarball that is downloaded as part of a script, there is only one directory in the tar file.  I need to change into that directory and do some stuff with the files in there, problem is, sometimes the directory name changes, and I dont konw what it will be (its actually a revision hash from git).  Is there a way to untar a file and then immediately go into the directory it creates?  Or is there a good way in bash to untar, look at the last folder created in the current directory and change into it?
0
Comment
Question by:mynamebecory2
  • 3
  • 2
5 Comments
 
LVL 30

Accepted Solution

by:
Kerem ERSOY earned 500 total points
ID: 24360318
Hi,

How about :

tar tvzf cgi-bin.tgz  | head -1 | cd $(awk '{ print $6 }')

This line will list the contents of a file named cgi-bin.tgz | get the first line of it then cd to that directory. If you add this at the end of a script then IT will automatiaclly go there :)

I hope this helps.

Cheers,
K.
0
 
LVL 1

Author Comment

by:mynamebecory2
ID: 24360381
Perfect, thnaks!
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 24360388
Yr Welcome :)
0
 
LVL 1

Author Comment

by:mynamebecory2
ID: 24378217
I forgot to hit accept solution didnt I ;)
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 24378809
It seems so :) anyway better late than nothing : )
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month15 days, 7 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question