To extract a single file or directory from a tarball archive, you can use the tar
command with the -x
option to extract, the -f
option to specify the archive file, and the -C
option to specify the destination directory. You can also use the --wildcards
option to specify a pattern that matches the file or directory you want to extract.
For example, to extract a single file called "file.txt" from a tarball archive called "archive.tar.gz", you can use the following command:
tar -xzf archive.tar.gz --wildcards 'file.txt' -C /path/to/destination/directory
To extract a directory called "directory" and all of its contents from the same tarball archive, you can use the following command:
tar -xzf archive.tar.gz --wildcards 'directory/*' -C /path/to/destination/directory
You can also use the --strip-components
option to remove leading directories from the extracted files. For example, to extract the contents of the "directory" directory directly into the destination directory, you can use the following command:
tar -xzf archive.tar.gz --wildcards 'directory/*' --strip-components=1 -C /path/to/destination/directory
Note that the tar
command can extract tarball archives in a variety of formats, including .tar
, .tar.gz
, .tar.bz2
, and others. The options and arguments you use may vary depending on the format of the tarball archive and the specific needs of your extraction.