How to tar a file in Linux using command line

The tar command in Linux is used to create and extract archive files. To create a .tar archive file from one or more files or directories, you can use the following syntax:

tar -cvf archive.tar file1 file2 directory1

In this example, -c option is used to create an archive, -v option is used for verbose output to display the files being archived, -f option is used to specify the archive file name (archive.tar in this case).

Here’s a brief explanation of the options used:

  • -c: create a new archive
  • -v: verbose output
  • -f: use archive file archive.tar

Note: You can also use the .tar.gz or .tgz extension to create a compressed archive file using the gzip compression utility. For example:

tar -czvf archive.tar.gz file1 file2 directory1

This will create a .tar.gz archive file called archive.tar.gz from the specified files and directories. The -z option is used to specify the use of gzip compression.

Leave a Comment