untar Command in Linux

Learn via video courses
Topics Covered

Overview

In this article, we'll explore the untar command in Linux, which is primarily used to extract files from tar archives. The tar command is widely used for backup and archiving purposes, as it can package multiple files into a single tarball. The untar command can help you to decompress and extract the files from these tarballs.

Linux untar Command Syntax

The syntax for the untar command is as follows:

Where:

  • options: These are flags and options that determine the behavior of the tar command.
  • archive-name: The name of the tarball to be processed.

untar Command Options:

  • -x: Extract files from an archive.
  • -f: Specify the archive file.
  • -v: Verbose mode, display the progress on the screen.
  • -C: Change to the specified directory before performing the operation.

Example Usages

  • Basic untar command usage:

    Output:

    Explanation: The '-x' option is used to extract files, and '-f' is used to specify the archive file.

  • Untar with verbose mode:

    Output:

    Explanation: The '-v' option enables verbose mode.

Tips

  • Always use '-f' option to specify the archive file, as not using it may lead to unexpected behavior.

  • Use the '-C' option to extract files to a specific directory instead of the current directory.

Advanced Use Cases of untar Command in Linux

  • Untar a gzipped tarball:

    Output:

    Explanation: The '-z' option tells tar to decompress the gzipped archive before extracting.

  • Untar a bzipped tarball:

    Output:

    Explanation: The '-j' option tells tar to decompress the bzipped archive before extracting.

  • Untar to a specific directory:

    Output:

    Explanation: The '-C' option is used to change the directory before extraction.

Conclusion

  • The untar command is used to extract files from tar archives.

  • Various options like '-x', '-f', '-v', and '-C' can be combined to control the extraction process.

  • It's essential to use the '-f' option to specify the archive file.

  • Advanced options like '-z' and '-j' can be used to handle compressed tarballs.

  • The '-C' option allows extracting files to a specific directory.