cheat.sheets:tar # tar# GNU version of the tar archiving utility# An approach to backing up the current user's HOME, using tar(1) and GZip# compression. Permissions (modes) will be preserved. The filename format will# be: UID:GID_DATE.tgz## Replace 'DEVICE' with whichever device is applicable to you, but note that it
# must be in the '/media/USER' (where USER is the username) directory, else# this won't work, unless you edit the formatting section of `printf`.tar-czvpf"$(printf'/media/%s/%s/%d:%d_%(%F)T.tgz'"$USER"'DEVICE'${UID:-`id-u`}${GID:-`id-g`}-1)""$HOME"
# Delete file 'xdm' from the archive given to the `-f` flag. This only works on# non-compressed archives, unfortunately, but those can always be uncompressed# first, then altered with the `--delete` flag, after which you can recompress.tar--delete-fxdm_edited.tar.gzxdm# Extract the contents of the given archive (which is not compressed) to the# destination given to the `-C` flag; not many seem to know of this flag.## If a destination (path given to `-C`) is not provided, the CWD will be used.tar-C/mnt-xvfTarball.tar cheat:tar ---tags:[compression]---# To extract an uncompressed archive:tar-xvf/path/to/foo.tar# To create an uncompressed archive:tar-cvf/path/to/foo.tar/path/to/foo/# To extract a .gz archive:tar-xzvf/path/to/foo.tgz# To create a .gz archive:tar-czvf/path/to/foo.tgz/path/to/foo/# To list the content of an .gz archive:tar-ztvf/path/to/foo.tgz# To extract a .bz2 archive:tar-xjvf/path/to/foo.tgz# To create a .bz2 archive:tar-cjvf/path/to/foo.tgz/path/to/foo/# To extract a .tar in specified Directory:tar-xvf/path/to/foo.tar-C/path/to/destination/# To list the content of an .bz2 archive:tar-jtvf/path/to/foo.tgz# To create a .gz archive and exclude all jpg,gif,... from the tgztarczvf/path/to/foo.tgz--exclude=\*.{jpg,gif,png,wmv,flv,tar.gz,zip}/path/to/foo/# To use parallel (multi-threaded) implementation of compression algorithms:tar-z...->tar-Ipigz...tar-j...->tar-Ipbzip2...tar-J...->tar-Ipixz... tldr:tar # tar# Archiving utility.# Often combined with a compression method, such as gzip or bzip.# More information: <https://www.gnu.org/software/tar>.# Create an archive from files:tarcftarget.tarfile1file2file3# Create a gzipped archive:tarczftarget.tar.gzfile1file2file3# Create a gzipped archive from a directory using relative paths:tarczftarget.tar.gz-Cpath/to/directory.# Extract a (compressed) archive into the current directory:tarxfsource.tar[.gz|.bz2|.xz]# Extract a (compressed) archive into the target directory:tarxfsource.tar[.gz|.bz2|.xz]-Cdirectory# Create a compressed archive, using archive suffix to determine the compression program:tarcaftarget.tar.xzfile1file2file3# List the contents of a tar file:tartvfsource.tar# Extract files matching a pattern:tarxfsource.tar--wildcards"*.html"# Extract a specific file without preserving the folder structure:tarxfsource.tarsource.tar/path/to/extract--strip-components=depth_to_strip$