9951 explained code solutions for 126 technologies


cli-tarHow do I use tar commands in Linux?


Tar is a command used to create and manipulate archives in Linux. To use tar, you must provide it with a few arguments to specify the desired action.

The basic syntax for tar is:

tar [options] [archive] [files]

Where options specify how the archive should be created or manipulated, archive is the name of the tar file you are creating or manipulating, and files are the files you are archiving.

The most commonly used options are:

  • -c: Create an archive
  • -x: Extract files from an archive
  • -t: List the contents of an archive
  • -v: Verbosely list the contents of an archive

For example, to create an archive called my_archive.tar containing all the files in the current directory, you would run:

tar -cvf my_archive.tar *

The output would be a list of all the files that were added to the archive:

file1
file2
file3
...

To extract the contents of the archive, you would run:

tar -xvf my_archive.tar

The output would be a list of all the files that were extracted from the archive:

file1
file2
file3
...

For more information, see the GNU Tar Manual.

Edit this code on GitHub