I have a project where I am downloading and compiling a bunch of files. The assumptions I can make about this files are:
- there will only be one top level directory
- the folder name doesn't necessarily match the tar.xz/gz filename (in other words something-1.3.5a.tar.gz might extract to a folder called something-1.3.5)
In order to lessen the amount of typing I have to do I wrote a small script, which among other things does the follow:
- extracts the tar.xz/gz file
- cds into the directory
My current hack is to do something like this:
test1=$(tar -axvf something-1.3.5a.tar.gz)
cd $(echo $test1 | cut -f1 -d" ")
Basically what this does is it captures the output of the extraction, and takes the first line (which is the top level directory) and then cds into it.
So, my question is this, is there a cleaner/better way of doing this?