Wazaterm » Linux Commands » tar

How to use tar Linux command

The tar command saves many files together into a single tape or disk archive and can restore individual files from the archive.

Usage

Create a compressed tar.gz archive file archive.tar for a directory backup in current working directory

    
      $ tar czvf archive.tar.gz ./backup/
    
  

Extract the contents from archive.tar.gz in the current directory

    
      $ tar xzvf archive.tar.gz
    
  

Create a tar archive file archive.tar for a directory backup in current working directory

    
      $ tar cvf archive.tar ./backup/
    
  

Extract the contents from archive.tar in the current directory

    
      $ tar xvf archive.tar
    
  

Extract the contents from archive.tar in /tmp directory

    
      $ tar xvf archive.tar -C /tmp