Say I have a
file.txt containing one line:
tar -czf archive.tar.gz file.txt
I can create a "gzipped archive" with the name
archive.tar.gz, which is to my knowledge the equivalent of doing
tar -cf archive.tar file.txt
Now, to extract
archive.tar.gz, I would use
tar -xzf archive.tar.gz
to get my
file.txt. This should be the equivalent of doing
gzip -d archive.tar.gz
tar -xf archive.tar
However, if I just use the command
tar -xf archive.tar.gz
without decompressing the file first through
gzip or the
--gzip option in tar, I still get my
file.txt and can read the content.
I changed the file ending from
archive.tar.gz to just
archive.tar and got the same results.
How does tar know that it has to decompress the file first given that the file ending can be changed by the user? Do I miss some essential knowledge about file storing that allows tar to notice the compression?