Tar command in Linux

tar

options:
-c: create the archive
-x: extract the archive
-f: create or extract with the specific archive filename
-t: displays or lists files in an archived file
-v: display info
-z: using gzip

-C: extract files into a specific directory, not the current directory

  1. Creating an uncompressed tar archive.

    1
    tar -cvf file.tar directory
  2. Creating a compressed tar archive by using gzip.

    1
    tar -cvzf file.tar.gz directory
  3. Extracting files from archive.

    1
    tar -xvf file.tar
  4. Extracting gzip tar archive.

    1
    tar -xvzf file.tar.gz
  5. Extracting files into a specific directory.

    1
    tar -xvf file.tar -C /var/html/
  6. Displays or lists files in the archived file.

    1
    tar -tvf file.tar