9951 explained code solutions for 126 technologies


cli-tarHow do I use the Unix tar options?


The tar command is a powerful tool in Unix-like systems for creating and managing archives. It is commonly used for file compression, archiving, and extraction.

The basic syntax for tar is tar [options] [archive] [file]. Here are some common options you can use with tar:

  • -c: Create an archive
  • -x: Extract files from an archive
  • -f: Specify an archive filename
  • -v: Verbosely list files processed
  • -z: Compress or decompress an archive using gzip

For example, to create an archive of a file named myfile.txt, you can use the following command:

tar -cvzf myfile.tar.gz myfile.txt

This will create a compressed archive of myfile.txt named myfile.tar.gz.

To extract the contents of the archive, you can use the following command:

tar -xvzf myfile.tar.gz

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

For more detailed information about the tar command, you can refer to the GNU tar manual.

Edit this code on GitHub