tar

tar, short for tape archive, is a versatile utility used for creating and manipulating archive files. Though originally developed for tape archives, it is still a very capable tool to help with compressing and extracting files. The Linux kernel is deployed via a tarball.

Basic Syntax

tar [options] [archive] [files...]

  • options: This specifies the actions to be performed on the archive file.
  • archive: This specifies the name of the archive file.
  • files: This specifies the files to be added to or extracted from the archive file.

Commonly Used Options

  • -c: This creates a new archive file.
  • -x: This extracts files from an archive file.
  • -f: This specifies the name of the archive file.
  • -z: This compresses the archive file using gzip.
  • -j: This compresses the archive file using bzip2.
  • -v: This displays verbose output during the archive creation or extraction process.
  • -t: This lists the contents of the archive file.
  • -C: This changes the directory before performing any actions.

Useful Examples

  • tar -cvf archive.tar file1 file2: This creates a new tarball file called archive.tar containing file1 and file2.
  • tar -xvf archive.tar: This extracts the contents of the archive.tar file.
  • tar -czvf archive.tar.gz folder: This creates a new compressed archive file called archive.tar.gz containing the contents of the folder directory using gzip for compression.
  • tar -xzvf archive.tar.gz: This extracts the tar.gz file named archive.
  • tar -xjvf archive.tar.bz2: This extracts the contents of the compressed archive.tar.bz2 file.
  • tar -tvf archive.tar: This lists the contents of the archive.tar file.
  • tar -C /home/user -xvf archive.tar: This extracts the contents of the archive.tar file into the /home/user directory.

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments

  1. […] Once installed, let’s first allow TCP traffic over your SSH port so that you don’t get locked out of…

  2. […] have the option to choose between Password and SSH key selection. Learn more about SSH keys here. It’s recommended…