The Linux Newbie Guide  ⇒    Fundamentals     Advanced     Supplement   Command Index   ENG⇒中
All rights reserved, please indicate the source when citing
  

tar - Archive and Restore Files




The tar command, short for "tape archive," is primarily used for bundling multiple files together into a single file for easier backup or transfer. The resulting bundled file typically has a ".tar" extension and is referred to as a "tarball." Note that tar itself doesn't perform compression; it simply bundles files together. Tarballs are often further compressed using compression tools to save space.

The syntax of the tar command is as follows:
tar [OPTIONS] [FILES]

Where "[FILES]" represents the files or directories you want to archive or extract.

Common options for the tar command include:

It's essential to place the "-f" option at the end, followed by the archive file's name, as shown in the example below.

Examples:
$ tar -cf file.tar * ←# Create an archive of all .txt files in the current directory and name it file.tar
tar -xf file.tar ←Extract the contents of file.tar to the current working directory

For more advanced operations, such as creating tarballs and detailed explanations of options and examples, you can refer to the provided link.