Extracting Specific Files
Extract a file called etc/default/sysstat from config.tar.gz tarball
#tar -ztvf config.tar.gz
#tar -zxvf config.tar.gz etc/default/sysstat
#tar -xvf {tarball.tar} {path/to/file}
This is also valid
#tar --extract --file={tarball.tar} {file}
Extract a directory called css from cbz.tar
##tar --extract --file=cbz.tar css
Wildcard based extracting
You can also extract those files that match a specific globbing pattern (wildcards). For example, to extract from cbz.tar all files that begin with pic, no matter their directory prefix, you could type:
#tar -xf cbz.tar --wildcards --no-anchored 'pic*'
To extract all php files, enter
#tar -xf cbz.tar --wildcards --no-anchored '*.php'
Where,
-x: instructs tar to extract files.
-f: specifies filename / tarball name.
-v: Verbose (show progress while extracting files).
-j : filter archive through bzip2, use to decompress .bz2 files.
-z: filter archive through gzip, use to decompress .gz files.
–wildcards: instructs tar to treat command line arguments as globbing patterns.
–no-anchored: informs it that the patterns apply to member names after any / delimiter.
Tar listing
Tar command provides the option to list files inside compressed tar ball. However mtools includes command called lz which gunzips and shows a listing of a gzip’d tar’d archive without extracting files.
For example, display listing of file called backup.tar.gz type command:
#lz backup.tar.gz
As you see lz provides a listing of a gzip’d tar’d archive, that is a tar archive compressed with the gzip command. It is not strictly necessary on Debian GNU/Linux (or other Linux/BSD/Solaris oses), because the GNU tar(1) program provides the same capability with the command:
#tar -tzf backup.tar.gz
No comments:
Post a Comment