9951 explained code solutions for 126 technologies


cli-tarHow do I use the tar command in Linux?


The tar command is a useful tool for compressing and archiving files in Linux. It can be used to create an archive file from a directory or a single file, or to extract an archive file.

Here is an example of how to use the tar command to create an archive file:

tar -cvf archive.tar /path/to/directory

This command will create an archive file called archive.tar from the directory /path/to/directory.

Here is an example of how to use the tar command to extract an archive file:

tar -xvf archive.tar

This command will extract the contents of the archive file archive.tar into the current directory.

The tar command has many options that can be used to customize its behavior. Here is a list of some of the most commonly used options:

  • -c: Create an archive file
  • -x: Extract an archive file
  • -v: Verbose output
  • -f: Specify the name of the archive file

For more information about the tar command, see the GNU tar manual.

Edit this code on GitHub