Solved

Untar'ing and changing directory

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

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…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now