Here is the scenario:
$ wget "http://foo.bar/repository/nightly/src/foo-latest.tar.gz"
$ tar -xzf foo-lastest.tar.gz
$ ls # the archive root contained a single directory named after software name and the build date
foo-20140115-0024
What you want is that in the end, the extracted files are placed in the directory foo, instead of foo-20140115-0024. You can of course move the directory once decompressed :
$ mv `tar -tvzf foo-latest.tar.gz | head -n1 | awk '{print $6}'` foo
Here is the question: is there a shorter/proper to perform the same result?
This should work:
$ mkdir foo
$ tar -C foo --strip-components=1 -xzf foo-latest.tar.gz
First we create output directory.
After that we use -C
to extract archive to that directory and --strip-components
to get rid of root directory from archive.