tar command in Linux and it perimeters

tar command in Linux and it perimeters

The tar command in Linux is used to create, manipulate, and extract files from tape archives (tarballs). It is commonly used to create backup archives, compress multiple files, and transfer large amounts of data efficiently.

The basic syntax of the tar command is as follows:

Bash
tar [options] [archive_file] [file(s) or directory]

Here’s a table explaining the main parameters and options of the tar command:

Parameter/OptionDescription
archive_fileSpecifies the name of the archive file to be created or extracted. If not provided, it operates on standard input/output.
-c, –createCreate a new archive.
-x, –extractExtract files from an archive.
-t, –listList the contents of an archive.
-v, –verboseEnable verbose mode, showing the processed files.
-f, –file=ARCHIVEUse the specified file as the archive.
-z, –gzipFilter the archive through gzip for compression (use with .tar.gz or .tgz extension).
-j, –bzip2Filter the archive through bzip2 for compression (use with .tar.bz2 or .tbz extension).
-r, –appendAppend files to the end of an archive.
-u, –updateOnly append files that are newer than the version in the archive.
-d, –diffCompare the contents of an archive with the file system.
-C, –directory=DIRChange to the specified directory before performing any operations.
–helpDisplay help and exit.
–versionOutput version information and exit.

Now, let’s see some examples of how to use the tar command:

  1. Create a tar archive from a directory:
Bash
tar -cvf archive.tar directory/

This will create a tar archive named archive.tar containing the contents of the directory/ directory.

  1. Extract files from a tar archive:
Bash
tar -xvf archive.tar

This will extract the contents of archive.tar to the current directory.

  1. Create a gzip-compressed tar archive:
Bash
tar -czvf archive.tar.gz directory/

This will create a gzip-compressed tar archive named archive.tar.gz from the contents of the directory/ directory.

  1. Extract files from a gzip-compressed tar archive:
Bash
tar -xzvf archive.tar.gz

This will extract the contents of the gzip-compressed tar archive archive.tar.gz to the current directory.

  1. Append files to an existing tar archive:
Bash
tar -rvf archive.tar additional_file

This will append additional_file to the existing archive.tar.

  1. List the contents of a tar archive:
Bash
tar -tvf archive.tar

This will list the contents of archive.tar without extracting them.

The tar command is a powerful tool for creating, extracting, and managing archive files, making it a crucial utility for file backups and data transfer. When used in combination with compression utilities like gzip or bzip2, it can efficiently store and transfer large amounts of data.

Total
0
Shares

Leave a Reply

Previous Post
gzip command in Linux and it perimeters

gzip command in Linux and it perimeters

Next Post
uncompress command in Linux and it perimeters

uncompress command in Linux and it perimeters

Related Posts