📜  untar - Shell-Bash (1)

📅  最后修改于: 2023-12-03 14:48:13.790000             🧑  作者: Mango

Untar - Shell-Bash

Untar is a command-line utility in Linux and Unix-like operating systems used to extract files from a tar archive. The tar archive combines multiple files into a single file, and the untar command is used to extract those files.

Syntax

The syntax for using the untar command is as follows:

tar -xf archive_name.tar
Options

The following are some of the options that can be used with the untar command:

  • -x: Extract files from the archive.
  • -f: Specifies the file to extract from.
  • -v: Verbose output, prints the list of files as they are extracted.
  • -c: Create a new archive.
  • -z: Compress the archive with gzip.
  • -j: Compress the archive with bzip2.
Examples
Extract files from an existing archive

To extract files from an existing tar archive, run the following command:

tar -xf archive_name.tar
Create a new archive

To create a new tar archive, run the following command:

tar -cf archive_name.tar file1 file2 file3
Extract a specific file

To extract a specific file from an archive, run the following command:

tar -xf archive_name.tar file_to_extract
Extract a compressed archive

To extract a compressed archive, use the appropriate option with the untar command.

For a gzip compressed archive, run the following command:

tar -xzf archive_name.tar.gz

For a bzip2 compressed archive, run the following command:

tar -xjf archive_name.tar.bz2
Conclusion

The untar command is an essential utility for working with tar archives in Linux and Unix-like operating systems. It provides a simple and efficient way to extract files from an archive, create new archives, and work with compressed archives.