tar.gz – Linux tar command examples

Introduction

In the Linux system, “tar” stands for tape archive. The tar command is to compress files and directories into a highly compress and uncompressed archive file commonly called tarball or tar.gz in Linux.

When we work with telecom system (Base-Stations, Routers, servers), they do dump the logs file in a hug amount – several GBs of data, which is difficult to transfer to another machines for offline debugging. Using tar commands, we can compress the files to a significate amount and transfer to local or remote machine for offline analysis.

Key Pointers

  • tar means in linux system is tape archive used to to combine multiple files into one
  • gzip is a compression tool used to reduce the size of a file
  • It is similar to 7-zip, winzip, winrar tools in Windows OS
  • gzip and tar are usually used to create tarballs that are compressed significantly
  • on linux system tar.gz file can be uncompressed using tar command while on windows machines it can uncompressed using 7-zip, winzip, winrar like tool

tar Command Syntax

Following figure show the tar command syntax for tar in Linux system. It shows the basic syntax, compressing and unpressing with tar and compressing and uncompressing the with the gzip.

  • Options indicates which operation executes on the files (creation, extraction, etc.). Following it the list of options available with tar command.
    •  -c : Creates Archive   
    • -x : Extract the archive  
    • -f : creates archive with given filename  
    • -t : displays or lists files in archived file  
    • -u : archives and adds to an existing archive file  
    • -v : Displays Verbose Information  
    • -A : Concatenates the archive files  
    • -z : zip, tells tar command that creates tar file using gzip  
    • -j : filter archive tar file using tbzip 
    • -W : Verify a archive file 
    • -r : update or add file or directory in already existed .tar file
  • archive-file is the file name and extension
  • file or directory  is a space-separated list for extraction or compression

Most Command Used tar Commonads with Example

  • Creating tar archive: Consider we have multiple files system.log under techplayon directory, we can tar them using following command
    • tar -cvf     <file_name.tar>   <file_directory>
    • tar -cvf      techplayon.tar        techplayon
    • tar -czvf    techplayon.tar.gz   techplayon

  • Extracting tar archive: Extraction process will untar/uncompressed the tar archive package to files or directory having the files as shown below. Here -x option is used to extract
    • tar -xvf     <file_name.tar>
    • tar -cvf      techplayon.tar
    • tar -czvf    techplayon.tar.gz

  • List  Content for tar archive: When we want to know the content of tar achive package, we can use the tf option as shown below.
    • tar    tf     <tar.gz_archive>
    • tar    tf       techplayon.tar.gz

Related Posts:



You may also like...