Results 1 to 4 of 4
I am writing a script that installs updates to an embedded system.
The script is required to extract a update tarball compressed with either .gz .bz2 or .xz.
I have ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 12-06-2011 #1
Extracting tarball without specifying compression format.
I am writing a script that installs updates to an embedded system.
The script is required to extract a update tarball compressed with either .gz .bz2 or .xz.
I have noticed on my gentoo system that I am able to decompress .tar.gz, .tar.bz2 and tar.xz compressed tarballs with only the -xvf option (ie without specifying the the compression filter -z -j or J options)
My question is: Can this behavior be expected for all versions of tar and will it be safe to assume this behavior if using the format "tar -xvf {*.tar.gz,*.tar.bz2,*.tar.xz}" in my script.
- 12-06-2011 #2
UPDATE:
.tar.gz and .tar.bz2 can be extracted using only the -xvf tar options. However tar.xz requires the -J option included otherwise tarball will not be extracted. Thus I will need to check the extension and use the compression filter option in my script.
- 12-06-2011 #3
May I suggest to rely on file, rather than a filename suffix?
e.g.:
Should be more accurate. Suffix checking can be an additional check, though.Code:file -i *.tar.* filename1.tar.gz: application/x-gzip; charset=binary filename2.tar.bz2: application/x-bzip2; charset=binary filename3.tar.xz: application/x-xz; charset=binary
You must always face the curtain with a bow.
- 12-06-2011 #4
Good plan. Thanks
Just a note on file though: file will determine that the file is either a gzip, bzip2 or a xz type file but won't tell you if it is a tar file unless you have already extracted the tar from the gzip, bzip2 or a xz type file.
In my script I was hoping to extract the whole tarball with only the tar command. If I could extract each type of compressed tarball with the simple command tar -xvf then I could cut down on a bit of logic. However tar.xz type tarballs require the compression filter option. No problem though. Will just add some checking logic to my script.
However, I strongly agree with you in rather using file types as outputted by the file command rather than relying on the file name wherever possible.Last edited by RobertF; 12-06-2011 at 10:59 AM.


1Likes
Reply With Quote
