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 calledarchive.tarcontainingfile1andfile2. -
tar -xvf archive.tar: This extracts the contents of thearchive.tarfile. -
tar -czvf archive.tar.gz folder: This creates a new compressed archive file calledarchive.tar.gzcontaining the contents of thefolderdirectory 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 compressedarchive.tar.bz2file. -
tar -tvf archive.tar: This lists the contents of thearchive.tarfile. -
tar -C /home/user -xvf archive.tar: This extracts the contents of thearchive.tarfile into the/home/userdirectory.
Leave a Reply