Applications 25 – Uncommon Options of tar Part 1

J

Jarret W. Buse

Guest
Applications 25 – Uncommon Options of tar Part 1

In the previous article, Applications 23 - Compression with gzip, the basis was that small files can help speed up a system. File compression is making files smaller than they are so they can read/written faster and transferred over the network/Internet quicker.

There is also the ability to write more compressed files on portable media such as USB, CD/DVD, etc. The tar compression method is another typical method used on Linux systems.

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.

  • --atime-preserve
When creating files, do not change the saved Access Time. Option needs to be used with the “-p” option to preserver permissions. To preserve the Access Time on archived files, the command would be “tar --atime-preserve -cpf preserved.tar”.

  • -b (--blocking-factor N)

The default block size is 20*512 (20). The value can be changed from 20 to another value as needed. To set a block size of 10, the command would be “tar -cb 10 -f blocksize.tar *”.

  • --backup BACKUP-TYPE

To backup your files into an archive, use the “--backup” option. The files specified and subfolders will be included in the archive. The “BACKUP-TYPE” can be one of the following:

    • numbered – number the backups
    • existing – create numbered backups of files that already have them, simple backups of the others
    • simple – always make simple backups

When using “simple”, the filenames will be what you specify. When using “numbered”, the names will have a number added to them. For example, if the file name is set to “Backup.tar”, the first file will be named “Backup.tar”. The second backup with the same filename will be named “Backup.tar.~1~” and so on. So, to backup the current folder and subfolders and files as a numbered backup, use the command “tar -cf Backup.tar --backup=numbered *”.

  • -C (--directory DIR)
When extracting files from an archive you can specify a different output folder. Using option “-C” the directory can be declared. For example, if an archive was made called “Backup.tar”, in the current folder, which needed to be extracted to a folder called “Out”, located in the Home folder, the command would be “tar -xf Backup.tar -C ~/Out”.

  • -l, (--check-links)
If hard links are to be included in the archive, use the “-l” option. For example, to backup the current folder, subfolders and files including hard links, use the command “tar -clf Backup.tar --backup=simple *”.

  • --checkpoint
When creating an archive, a checkpoint can be written to the display when each folder is done. Simply add the “--checkpoint” option to the command. For example, to archive the current folder, use the command “tar -cf Output.tar –checkpoint”.

  • -f (--file [HOSTNAME:]FILE)

When specifying any output filename for the archive, use the “-f” option followed by a space and then the filename which is used as an output filename. For example, to create a file called “main.tar” containing a local file called “test.txt”, use the command “tar -cf main.tar test.txt”.

  • -F (--info-script FILE, --new-volume-script FILE)
If a script needs to be executed after each volume is created, use the “-F” option. The command is useful when backing up to a tape drive. When each tape is full, a new volume needs to replace the old one (tape). A script can perform a network broadcast to alert someone to change the tape. If restoring a volume, the script can alert someone to change the tape as well. The command to run a script called “new-volume” when creating an archive called “archive.tar” would be “tar -cf archive.tar -F new-volume .”.

  • --force-local
If a filename is a local file, but appears as a remote file or on a tape drive, the “--force-local” option will make it look locally. For example, if the local system is call “Server1” and the filename is “File1” the command could be “tar -cf [email protected]:File1 --force-local .”.

  • --format FORMAT

If the output archive format needs to be changed, you can use the “--format” option. The various “FORMAT” options are:

    • v7 - Creates an archive that is compatible with Unix V7 tar
    • oldgnu - Creates an archive that is compatible with GNU tar version 1.12 or earlier
    • gnu - Creates archive in GNU tar 1.13 format. Basically it is the same as `oldgnu' with the only difference in the way it handles long numeric fields
    • Ustar - Creates a POSIX.1-1988 compatible archive
    • Posix - Creates a POSIX.1-2001 archive

This is the first part of uncommon tar options. Please continue reading over the next article to complete the uncommon tar options.
 

Attachments



Members online


Latest posts

Top