Tutorial by Examples

This creates a simple archive of a folder : tar -cf ./my-archive.tar ./my-folder/ Verbose output shows which files and directories are added to the archive, use the -v option: tar -cvf ./my-archive.tar ./my-folder/ For archiving a folder compressed 'gzip', you have to use the -z option : ta...
There is an example for extract a folder from an archive in the current location : tar -xf archive-name.tar If you want to extract a folder from an archive to a specfic destination : tar -xf archive-name.tar -C ./directory/destination
There is an example of listing content : tar -tvf archive.tar The option -t is used for the listing. For listing the content of a tar.gz archive, you have to use the -z option anymore : tar -tzvf archive.tar.gz
If you want to extract a folder, but you want to exclude one or several folders during the extraction, you can use the --exclude option. tar -cf archive.tar ./my-folder/ --exclude="my-folder/sub1" --exclude="my-folder/sub3" With this folder tree : my-folder/ sub1/ su...
To strip any number of leading components, use the --strip-components option: --strip-components=NUMBER strip NUMBER leading components from file names on extraction For example to strip the leading folder, use: tar -xf --strip-components=1 archive-name.tar
List the contents of an archive file without extracting it: tar -tf archive.tar.gz Folder-In-Archive/ Folder-In-Archive/file1 Folder-In-Archive/Another-Folder/ Folder-In-Archive/Another-Folder/file2

Page 1 of 1