?
Solved

Untar'ing and changing directory

Posted on 2009-05-11
5
Medium Priority
?
339 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
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 navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

752 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