Untar'ing and changing directory

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?
LVL 1
mynamebecory2Asked:
Who is Participating?
 
Kerem ERSOYConnect With a Mentor PresidentCommented:
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
 
mynamebecory2Author Commented:
Perfect, thnaks!
0
 
Kerem ERSOYPresidentCommented:
Yr Welcome :)
0
 
mynamebecory2Author Commented:
I forgot to hit accept solution didnt I ;)
0
 
Kerem ERSOYPresidentCommented:
It seems so :) anyway better late than nothing : )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.