You can use "tar -xf filename". I personally don't specify a compression method when extracting files from an archive.
You said:
Tar -czvf /home/root2/example.tar.gz /etc
Then I can uncompress using this
Tar -xf /home/root2/example.tar.gz
------
Well, kind of. I'm going to be specific here.
First, the command in tar, not Tar
If a tarball was created with this command: tar -czvf /home/root2/example.tar.gz /etc, you would want to decompress it into an empty directory.
To decompress:
mkdir -p /home/root2/example-backup
cd /home/root2/example-backup
tar -xf /home/root2/example.tar.gz
So... the -z (gzip) option is used when creating the compressed tarball, but is not used when extracting it.
You can use "tar -xf filename". I personally don't specify a compression method when extracting files from an archive.
As @Lisenet mentioned, tar -xf <filename> will extract the compressed archive, even though the compression option is not specified.
With good practices, you'll already know the compression type because of the file's extension: example.tar.gz or example.tar.bz2
If you need to know what the compression type is (maybe there's no extension), use:
file <filename> and it will tell you, for example:
[root@clientx ~]# file etc-backup
etc-backup: gzip compressed data, last modified: Wed Jun 10 21:50:16 2020, from Unix, original size 27176960
(Although I may be mistaken, I thought older versions of the tar command required the proper compresstion option type to be specified when extracting a tarball; in other words, it would not auto-detect the compression that was used to create the file. Even so, it doesn't hurt to include the option, as long as it is the correct one. I used to do it all the time by habit.)
You said:
Tar -czvf /home/root2/example.tar.gz /etc
Then I can uncompress using this
Tar -xf /home/root2/example.tar.gz
------
Well, kind of. I'm going to be specific here.
First, the command in tar, not Tar
If a tarball was created with this command: tar -czvf /home/root2/example.tar.gz /etc, you would want to decompress it into an empty directory.
To decompress:
mkdir -p /home/root2/example-backup
cd /home/root2/example-backup
tar -xf /home/root2/example.tar.gz
So... the -z (gzip) option is used when creating the compressed tarball, but is not used when extracting it.
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.