How to tar a file in Linux using command line

How to tar a file in Linux using command line

To tar (create a tar archive) a file in Linux using the command line, you can use the tar command.

The basic syntax for creating a tar archive is as follows:

r‮:ot refe‬lautturi.com
tar -cvf <archive>.tar <files>

Here's what the options and arguments mean:

  • -c: Create a new tar archive.
  • -v: Verbose mode. This option causes tar to display the names of the files as it processes them.
  • -f: Specifies the name of the tar archive.
  • <archive>.tar: The name of the tar archive to create.
  • <files>: The names of the files or directories to include in the tar archive.

For example, to create a tar archive of the file1.txt and file2.txt files, you can use the following command:

tar -cvf archive.tar file1.txt file2.txt

This will create a tar archive called archive.tar that includes the file1.txt and file2.txt files. The -v option will cause tar to display the names of the files as it processes them.

You can also use the -z option to compress the tar archive using gzip. For example, to create a gzip-compressed tar archive of the file1.txt and file2.txt files, you can use the following command:

tar -czvf archive.tar.gz file1.txt file2.txt

This will create a gzip-compressed tar archive called archive.tar.gz that includes the file1.txt and file2.txt files.

Created Time:2017-10-29 22:08:38  Author:lautturi