Tar Extract a Single File(s) From a Large Tarball

To extract a single file or multiple files from a large tarball in Linux, you can use the tar command with the --extract or -x option followed by the --file or -f option to specify the tarball file, and then provide the name(s) of the file(s) you want to extract.

Here’s an example of how to extract a single file from a tarball:

tar -xzf mytarball.tar.gz path/to/myfile.txt

This command will extract the myfile.txt file from the mytarball.tar.gz tarball located in the current directory, and place it in the path/to/ directory.

If you want to extract multiple files, you can list them all after the tarball file name, like this:

tar -xzf mytarball.tar.gz file1.txt file2.txt file3.txt

This will extract the three specified files from the tarball.

If the files you want to extract are located in a directory inside the tarball, you can include the path to the directory in the file name, like this:

tar -xzf mytarball.tar.gz path/to/my/directory/myfile.txt

This will extract the myfile.txt file from the mytarball.tar.gz tarball, which is located in the path/to/my/directory/ directory inside the tarball, and place it in the path/to/my/directory/ directory on your system.

Note that if you want to extract all the files from the tarball, you can simply run the tar command with the --extract or -x option and the --file or -f option followed by the tarball file name, like this:

tar -xzf mytarball.tar.gz

This will extract all the files from the tarball into the current directory.

Leave a Comment