
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,277 Views
I'm very new to linux, planning to go for rhcsa first. I went to do some small lab exercise. I come across this question
Eg run the tar command and uncompress and restore both archives without specifying the compression tools used
I'm not sure what this really meant, from what I know is
Tar -xzvf example.tar.gz
Tar -xjvf example.tar.bz2
Accepted Solutions


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,273 Views
You can use "tar -xf filename". I personally don't specify a compression method when extracting files from an archive.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,259 Views
So you mean to say that eg
Tar -czvf /home/root2/example.tar.gz /etc
Then I can uncompress using this
Tar -xf /home/root2/example.tar.gz


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,238 Views
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.
Estrella Mountain Community College


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,274 Views
You can use "tar -xf filename". I personally don't specify a compression method when extracting files from an archive.


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,268 Views
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.)
Estrella Mountain Community College

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,260 Views
So you mean to say that eg
Tar -czvf /home/root2/example.tar.gz /etc
Then I can uncompress using this
Tar -xf /home/root2/example.tar.gz


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,239 Views
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.
Estrella Mountain Community College

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,224 Views
Thanks for the tip, I guess when I type tar it went to Tar