Applications 29 – Uncommon Options of tar Part 5

J

Jarret W. Buse

Guest
Applications 29 – Uncommon Options of tar Part 5

This article continues the uncommon options of the tar command.

Recall the basic syntax for using tar is:

tar <operation> [option] [folder/file]

The non-common options for tar are not often used, but you should have an idea of what else can be done with tar.

-R, --record-number

If you need to see the record number as an archive is parsed (listing or extracting), use the “-R” option. When listing the files in an archive, the block number is listed with each file. With an extraction, the block number is listed only with the final block, or End of File (EOF). If you want the blocks shown during an extraction, use the verbose (-v) option. So, to view the contents of a tar, called “Data.tar”, and see the starting block number for each file use the command “tar -tRf Data.tar”.

--record-size SIZE

In some cases, when a database is placed in a tar file, a database contains records. Records can be of variable length, but usually they are of a set length. To access data from the tar file, where the records are of a set length, use the “--record-size” option. Specify the set record length with the length value after the option. For instance, to list the file contents of “Database.tar” and read the contents at a record length of 1,000 bytes, use the command “tar -tf Database.tar –record-size 1024”. The record size must be in increments of 512 bytes.

--recursion

Normally, when creating a tar file only the files in the current folder are included. To also include subfolders and files use the “--recursion” option. To archive a folder called “Docs” with all of its files as well as subfolders and files to a file called “Documents.tar”, the command would be “tar -cf Documents.tar --recursive Docs/”.

--recursive-unlink

When extracting files from an archive, files may exist in the folders which have been added since the archive was created. To place the files and folders to be an exact match to the archive, the files and folders should be deleted before extraction. To remove the folders and files, use the “--recursive-unlink” option. To extract files and folders from “Documents.tar” into the “Data” folder while removing all files first, use the command “tar -xf Documents.tar --recursive-unlink Data/*”.

--remove-files

Sometimes, to save space, files will be deleted after being placed into an archive. To delete these files, use the “--remove-files” option. To archive a folder called “Docs” with all of its files as well as subfolders and files to a file called “Documents.tar”, the command would be “tar -cf Documents.tar --recursive Docs/”. Now, to also delete the files when they are archived, extend the command to “tar -cf Documents.tar --recursive --remove-files Docs/”.

--rmt-command CMD

In cases where a tape server is being used to store the tar, the program “rmt” is not used. The “rmt” program sends commands to the tape device. Instead of using “rmt”, you can send a command (“cmd”) to the tape server.

--rsh-command CMD

In cases where a tape server is being used to store the tar, the program “rsh” is not used when a remote shell is not needed. The “rsh” program sends commands to the tape device. Instead of using “rsh”, you can send a command (“cmd”) to the tape server.

-s, --same-order, --preserve-order

The “-s” option is used to compare, list or extraction of files. The option causes the list of files to be managed in the order they appear in the archive and not to sort them alphabetically. The procedure can help reduce memory usage with large file lists in a tar. To list the files in the “Documents.tar” file in the order they occur, use the command “tar -tsf Documents.tar”.

-S, --sparse

When creating or updating tar files there can be spaces in the file causing it to be larger. The “-S” option can remove the space, or sparseness, to reduce the file size, if possible. To archive a folder called “Docs” with all of its files as well as subfolders and files to a file called “Documents.tar” removing sparsness, the command would be “tar -cSf Documents.tar --recursive Docs/”

--same-owner

When extracting files from an archive the original ownership needs to be maintained. To keep the original ownership use the “--same-owner” option. To extract files and folders from “Documents.tar” into the “Data” folder and keeping the original ownership, use the command “tar -xf Documents.tar –same-owner Data/*”.

--show-defaults

To see the defaults of tar, use the command “tar --show-defaults”.

--show-omitted-dirs

When listing or extracting an archive you can get information about omitted directories when you are specifying specific items to list or extract. The option, “--show-omitted-dirs”, can be helpful to see which folders are skipped in case one needs to be included. To show the contents of a directory called “Articles” in an archive named “Backup.tar”, but omit all other folders (still listing the folder names), use the command “tar -tf Backup.tar --show-omitted-dirs Articles”.

As usual, practice these options so you are aware that they exist and hopefully can spot them on the Linux+ Certification Exam.
 

Attachments

  • slide.jpg
    slide.jpg
    32.9 KB · Views: 226,044

Members online


Latest posts

Top