Solved

Untar'ing and changing directory

Posted on 2009-05-11
5
335 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 125 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

839 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