### tar-snapshot-edit: Example session showing inspection and update Source: https://www.gnu.org/software/tar/manual/html_node/Fixing-Snapshot-Files.html Example session demonstrating how to inspect device numbers in two snapshot files and then update them using the -b and -r options. The -b option creates a backup copy of the snapshot file, and -r takes a comma-separated list of olddev-newdev pairs. ```shell $ `tar-snapshot-edit root_snap.0 boot_snap.0` File: root_snap.0 Detected snapshot file version: 2 Device 0x0000 occurs 1 times. Device 0x0003 occurs 1 times. Device 0x0005 occurs 1 times. Device 0x0013 occurs 1 times. Device 0x6801 occurs 1 times. Device 0x6803 occurs 6626 times. Device 0xfb00 occurs 1 times. File: boot_snap.0 Detected snapshot file version: 2 Device 0x6801 occurs 3 times. ``` ```shell $ `tar-snapshot-edit -b -r 0x6801-0x6901,0x6803-0x6903 root_snap.0 boot_snap.0` File: root_snap.0 Detected snapshot file version: 2 Updated 6627 records. File: boot_snap.0 Detected snapshot file version: 2 Updated 3 records. ``` -------------------------------- ### Simplified example without explicit --recursion Source: https://www.gnu.org/software/tar/manual/html_node/Position_002dSensitive-Options.html A footnote clarifies that --recursion is the default and can be omitted. The same example can be written without it. ```shell tar -cf a.tar /usr --no-recursion /var/* ``` -------------------------------- ### opt-doc-col example: adjusting help output column Source: https://www.gnu.org/software/tar/manual/html_node/Configuring-Help-Summary.html Shows how setting ARGP_HELP_FMT=opt-doc-col changes the column where option descriptions start. Default is 29. If the value is too small, the description wraps to a separate line. ```shell $ `tar --help|grep ARCHIVE` -f, --file=ARCHIVE use archive file or device ARCHIVE $ `ARGP_HELP_FMT=opt-doc-col=19 tar --help|grep ARCHIVE` -f, --file=ARCHIVE use archive file or device ARCHIVE $ `ARGP_HELP_FMT=opt-doc-col=9 tar --help|grep ARCHIVE` -f, --file=ARCHIVE use archive file or device ARCHIVE ``` -------------------------------- ### tar --create --verbose example Source: https://www.gnu.org/software/tar/manual/html_node/create-verbose.html Use the --verbose (-v) option with tar --create to list files as they are archived. The example shows the command and its output, which lists each file name on a separate line. ```shell $ `tar --create --verbose --file=collection.tar blues folk jazz` blues folk jazz ``` -------------------------------- ### Example of split member names Source: https://www.gnu.org/software/tar/manual/html_node/Split-Recovery.html Example showing the member names when var/longfile is split across three volumes. ```text var/longfile var/GNUFileParts/longfile.1 var/GNUFileParts/longfile.2 ``` -------------------------------- ### tar -c --checkpoint=1000 /var Source: https://www.gnu.org/software/tar/manual/html_node/checkpoints.html Equivalent to the previous example because echo is the default action. ```shell $ `tar -c --checkpoint=1000` /var ``` -------------------------------- ### Example dd command for extended header extraction Source: https://www.gnu.org/software/tar/manual/html_node/Sparse-Recovery.html Concrete example of the dd command using the values from the earlier listing. ```shell $ `dd if=arc.tar of=xhdr bs=512 skip=56 count=7` ``` -------------------------------- ### restore --level=1 - start restore from level 1 backup Source: https://www.gnu.org/software/tar/manual/html_node/Scripted-Restoration.html Starts restoring from the given backup level (1) instead of the default level 0, useful when only recent backups are needed. ```shell restore --level=1 ``` -------------------------------- ### ARGP_HELP_FMT boolean variable assignment examples Source: https://www.gnu.org/software/tar/manual/html_node/Configuring-Help-Summary.html Shows how to set a boolean variable to true (by naming it) or false (by prefixing with 'no-'). ```text # Assign true value: dup-args # Assign false value: no-dup-args ``` -------------------------------- ### Strip two leading directory components Source: https://www.gnu.org/software/tar/manual/html_node/transform.html Example 2: strips two leading directory components, equivalent to --strip-components=2. ```shell $ `tar --transform='s,/*[^/]*/[^/]*/,,' -x -f arch.tar` ``` -------------------------------- ### doc-opt-col example: help output with doc-opt-col=6 Source: https://www.gnu.org/software/tar/manual/html_node/Configuring-Help-Summary.html Shows the effect of setting doc-opt-col to 6, which shifts the doc options (format names) to column 6. ```text -H, --format=FORMAT create archive of the given format. FORMAT is one of the following: gnu GNU tar 1.13.x format oldgnu GNU format as per tar <= 1.12 pax POSIX 1003.1-2001 (pax) format posix same as pax ustar POSIX 1003.1-1988 (ustar) format v7 old V7 tar format ``` -------------------------------- ### Example UID translation map file Source: https://www.gnu.org/software/tar/manual/html_node/override.html A sample configuration file for the --owner-map option, demonstrating mapping of UID 10 to 'bin' and 'smith' to 'root' with UID 0. ```text +10 bin smith root:0 ``` -------------------------------- ### tar --verbose --acls detailed listing Source: https://www.gnu.org/software/tar/manual/html_node/Extended-File-Attributes.html Example output when listing with two or more --verbose options and --acls. The ACL is printed after each file entry, starting with 'a:'. ```text -rw-r--r--+ smith/users 110 2016-03-16 16:07 file a: user::rw-,user:gray:-w-,group::r--,mask::rw-,other::r-- ``` -------------------------------- ### doc-opt-col example: default help output for --format Source: https://www.gnu.org/software/tar/manual/html_node/Configuring-Help-Summary.html Shows the default layout of the help output for the --format option, where format names are doc options. ```text -H, --format=FORMAT create archive of the given format. FORMAT is one of the following: gnu GNU tar 1.13.x format oldgnu GNU format as per tar <= 1.12 pax POSIX 1003.1-2001 (pax) format posix same as pax ustar POSIX 1003.1-1988 (ustar) format v7 old V7 tar format ``` -------------------------------- ### tar --verbose --xattrs detailed listing Source: https://www.gnu.org/software/tar/manual/html_node/Extended-File-Attributes.html Example output when listing with two or more --verbose options and --xattrs. Each extended attribute is listed on a separate line starting with two spaces and 'x:' followed by length and name. ```text -rw-r--r--* smith/users 110 2016-03-16 16:07 file x: 7 user.mime_type x: 32 trusted.md5sum ``` -------------------------------- ### tar --verify -cf /tmp/foo.tar /etc Source: https://www.gnu.org/software/tar/manual/html_node/verify.html Example command showing the use of --verify with --create. Note that tar strips leading slashes, so this works as desired only if the working directory is /. ```shell tar --verify -cf /tmp/foo.tar /etc ``` -------------------------------- ### tar --create --verbose --blocking-factor=20 --file=/dev/rmt0 Source: https://www.gnu.org/software/tar/manual/html_node/Long-Options.html Example of using long options with arguments, demonstrating the --file option with an equal sign. ```shell $ `tar --create --verbose --blocking-factor=20 --file=/dev/rmt0` ``` -------------------------------- ### Create a multi-volume archive with --tape-length (G) Source: https://www.gnu.org/software/tar/manual/html_node/Multi_002dVolume-Archives.html Equivalent to the previous example, but uses the 'G' suffix to specify the tape length in gigabytes. This also automatically selects --multi-volume. ```shell $ `tar --create --tape-length=4G --file=/dev/tape files` ``` -------------------------------- ### Format 2 format identifier example Source: https://www.gnu.org/software/tar/manual/html_node/Snapshot-Files.html Example of the format identifier line in a format 2 snapshot file, showing the GNU tar version and format version. ```text GNU tar-1.35.90-2 ``` -------------------------------- ### Create archive of directory with tar --create --verbose --file Source: https://www.gnu.org/software/tar/manual/html_node/create-dir.html Creates an archive named music.tar containing the practice directory. The --verbose flag lists files as they are added. ```shell $ `tar --create --verbose --file=music.tar practice` ``` -------------------------------- ### Output of tar --create --verbose --file=music.tar practice Source: https://www.gnu.org/software/tar/manual/html_node/create-dir.html Shows the expected output when archiving the practice directory. The archive file collection.tar is also included because it is inside the directory. ```shell practice/ practice/blues practice/folk practice/jazz practice/collection.tar ``` -------------------------------- ### Prepend /prefix/ to each file name Source: https://www.gnu.org/software/tar/manual/html_node/transform.html Example 4: prepends /prefix/ to each file name during extraction. ```shell $ `tar --transform 's,^,/prefix/,' -x -f arch.tar` ``` -------------------------------- ### tar --owner=root example Source: https://www.gnu.org/software/tar/manual/html_node/override.html Forces the owner of archive members to the user name root. ```shell $ `tar -c -f archive.tar --owner=root .` ``` -------------------------------- ### Use -C option in file list to change directories Source: https://www.gnu.org/software/tar/manual/html_node/files.html Shows a file list (list) that uses -C to switch to /etc and /lib, and the tar command that creates foo.tar from it. The resulting archive contains passwd, hosts, and libc.a. ```shell $ `cat list` -C/etc passwd hosts -C/lib libc.a $ `tar -c -f foo.tar --files-from list` ``` -------------------------------- ### Create archives bluesrock.tar and folkjazz.tar Source: https://www.gnu.org/software/tar/manual/html_node/concatenate.html Creates two small archives from the practice files. The first command creates bluesrock.tar from files 'blues' and 'rock'; the second creates folkjazz.tar from 'folk' and 'jazz'. Output shows the member names as they are added. ```shell $ `tar -cvf bluesrock.tar blues rock` blues rock $ `tar -cvf folkjazz.tar folk jazz` folk jazz ``` -------------------------------- ### Verbose output for a specific member Source: https://www.gnu.org/software/tar/manual/html_node/list.html Example verbose output showing owner, size, and date for the member. ```shell -rw-r--r-- myself/user 62 1990-05-23 10:55 folk ``` -------------------------------- ### Copy directory hierarchy with long options and -C Source: https://www.gnu.org/software/tar/manual/html_node/copy-directory-hierarchy.html Same as the second example but using long option forms (--directory, --create, --file, --extract) with -C. ```shell $ `tar --directory sourcedir --create --file=- . \ | tar --directory targetdir --extract --file=-` ``` -------------------------------- ### tar --owner=0 example Source: https://www.gnu.org/software/tar/manual/html_node/override.html Forces the owner of archive members to user ID 0 (root). ```shell $ `tar -c -f archive.tar --owner=0 .` ``` -------------------------------- ### tar --help output excerpt showing main operation mode options Source: https://www.gnu.org/software/tar/manual/html_node/Configuring-Help-Summary.html Shows the default layout of the help summary, with short options, long options, and descriptions. This is the output that can be customized via ARGP_HELP_FMT. ```text Main operation mode: -A, --catenate, --concatenate append tar files to an archive -c, --create create a new archive -d, --diff, --compare find differences between archive and file system --delete delete from the archive ``` -------------------------------- ### Extract usr/ hierarchy into usr/local/ Source: https://www.gnu.org/software/tar/manual/html_node/transform.html Example 1: extracts the usr/ hierarchy into usr/local/ using a transform expression. ```shell $ `tar --transform='s,usr/,usr/local/,' -x -f arch.tar` ``` -------------------------------- ### Multiple checkpoint actions with echo, sleep, and exec Source: https://www.gnu.org/software/tar/manual/html_node/checkpoints.html Combines multiple --checkpoint-action options in one command. This example displays two messages, pauses for 30 seconds, and executes /sbin/cpoint. It also shows that --checkpoint-action can be used without --checkpoint, in which case the default frequency (every 10th record) is used. ```shell $ `tar -c -f arc.tar \ --checkpoint-action='\aecho=Hit %s checkpoint #%u' \ --checkpoint-action='echo=Sleeping for 30 seconds' \ --checkpoint-action='sleep=30' \ --checkpoint-action='exec=/sbin/cpoint'` ``` -------------------------------- ### tar -c -v -b 20 -f /dev/rmt0 Source: https://www.gnu.org/software/tar/manual/html_node/Short-Options.html Example of separated short options with arguments directly following each option that requires one. Demonstrates the standard Unix style for tar commands. ```shell $ `tar -c -v -b 20 -f /dev/rmt0` ``` -------------------------------- ### Output of tar --list for collection.tar Source: https://www.gnu.org/software/tar/manual/html_node/list.html Example output showing the member names listed by the previous command. ```shell blues folk jazz ``` -------------------------------- ### Warnings for non-PAX-aware tar Source: https://www.gnu.org/software/tar/manual/html_node/Split-Recovery.html Example warnings and file extractions when using a tar implementation that is not PAX-aware. These warnings can be ignored. ```shell $ `tar xf vol-1.tar` var/PaxHeaders/longfile: Unknown file type 'x', extracted as normal file Unexpected EOF in archive $ `tar xf vol-2.tar` tmp/GlobalHead.1: Unknown file type 'g', extracted as normal file GNUFileParts/PaxHeaders/sparsefile.1: Unknown file type 'x', extracted as normal file ```