How to extract tgz file in Linux

centos7
bash
shell

#1

I need to restore backup of failed upload. File store in nas server as www-data.tgz. I downloaded www-data.tgz from nas box and uploaded using scp to my CentOS 7 Linux server. How do I extract tgz file in Linux? What command need to be run when I ssh using putty.exe?


#2

Use the following tar command:

tar -xzvf data.tgz

The tar options are as follows to extract tgz file in Linux:

  1. -x : Extract file
  2. -z : Deal with compressed file i.e. filter the archive through gzip
  3. -v : Verbose output i.e. show progress
  4. -f : File, work on data.tgz file.
  5. -C /path/to/dir/ : Extract files in /path/to/dir/ directory instead of the current directory on Linux
  6. -t : List all files stored in an archive

How to Extract a data.tgz file in a directory named /tmp/ in Linux

Try

tar -xzvf data.tgz -C /tmp

How to list files in a data.tgz file

Use:

tar -ztvf data.tgz
tar -ztvf data.tgz | more
tar -ztvf data.tgz | grep something

For more info see my FAQ:

You can read man page of tar command by typing the following command:

man tar