Highlighted
Mission Specialist
Mission Specialist
  • 182 Views

Tar command without specifying compression tool

Jump to solution
Hi all,
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
Labels (1)
Tags (1)
0 Kudos
3 Solutions

Accepted Solutions
Highlighted
Starfighter Starfighter
Starfighter
  • 178 Views

Re: Tar command without specifying compression tool

Jump to solution

You can use "tar -xf filename". I personally don't specify a compression method when extracting files from an archive.

View solution in original post

Reply
Loading...
Highlighted
Mission Specialist
Mission Specialist
  • 164 Views

Re: Tar command without specifying compression tool

Jump to solution
Hi @Lisenet and tracy_baker, firstly I want to thank both of you to clear my doubt, sorry to ask a dumb question here
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

View solution in original post

0 Kudos
Reply
Loading...
Highlighted
Starfighter Starfighter
Starfighter
  • 143 Views

Re: Tar command without specifying compression tool

Jump to solution

@Tahaik 

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.

Program Lead at Arizona's first Red Hat Academy, est. 2005
Estrella Mountain Community College

View solution in original post

0 Kudos
Reply
Loading...
5 Replies
Highlighted
Starfighter Starfighter
Starfighter
  • 179 Views

Re: Tar command without specifying compression tool

Jump to solution

You can use "tar -xf filename". I personally don't specify a compression method when extracting files from an archive.

View solution in original post

Reply
Loading...
Highlighted
Starfighter Starfighter
Starfighter
  • 173 Views

Re: Tar command without specifying compression tool

Jump to solution

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.)

Program Lead at Arizona's first Red Hat Academy, est. 2005
Estrella Mountain Community College
Reply
Loading...
Highlighted
Mission Specialist
Mission Specialist
  • 165 Views

Re: Tar command without specifying compression tool

Jump to solution
Hi @Lisenet and tracy_baker, firstly I want to thank both of you to clear my doubt, sorry to ask a dumb question here
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

View solution in original post

0 Kudos
Reply
Loading...
Highlighted
Starfighter Starfighter
Starfighter
  • 144 Views

Re: Tar command without specifying compression tool

Jump to solution

@Tahaik 

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.

Program Lead at Arizona's first Red Hat Academy, est. 2005
Estrella Mountain Community College

View solution in original post

0 Kudos
Reply
Loading...
Highlighted
Mission Specialist
Mission Specialist
  • 129 Views

Re: Tar command without specifying compression tool

Jump to solution
Hi tracy_baker
Thanks for the tip, I guess when I type tar it went to Tar
0 Kudos
Reply
Loading...
Join the discussion
You must log in to join this conversation.