Applications 26 – Uncommon Options of tar Part 2


Jarret W. Buse

Applications 26 – Uncommon Options of tar Part 2

This article continues the uncommon options of the tar command.

Recall the basic syntax for using tar is:

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

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

  • -g, --listed-incremental=F
When creating backups, it may be best to perform incremental backups for saving space. The “-g” option allows you to create the incremental backups. New files added since the backup snapshot will be included in the new backup. When creating a backup, use the “-g” option to create a snapshot file. If I wanted to create a backup of a folder called “Tron” and create a snapshot at the same time called “Tron.snap”, the command would be “tar -cf Backup.tar --backup=numbered -g Tron.snap Tron/*”. When creating an incremental backup, the command would be “tar -cf Backup.tar --backup=numbered --listed-incremental=Backup.snap Tron/*”. Here, you can see that tar is being given the information to the SNAPSHOT file and will backup only the files which are newer than when the backup was created.

  • -G, --incremental
Same as “-g”, but used for backwards compatibility with older GNU-format backups.

  • -h, --dereference
Used to archive the file which a symbolic link points to, and not the link itself. For example, if the file “File1.doc” was a symlink, the file could be backed up with the command “tar -chf BackupFile1.tar File1.doc”.

  • --help

The “--help” option is used to display help information. No other options or commands are needed. The command is “tar --help”.

  • -i, --ignore-zeros
The option is used to ignore blocks in the archive which are all zeroes. For example, to backup “File1.doc” and remove zeroed blocks, the command would be ““tar -cif File1Zeroed.tar File1.doc”.

  • --ignore-case

If you need to ignore the case of filenames when matching filenames use the option “--ignore-case”. The option is used with “--exclude” which is used to list excluded files. By combining the two, the exclude list is not case-sensitive. To backup all files from the “Pics” folder and exclude all files with a filename starting with “images”, use the command “tar -cf Backupexc.tar --exclude image* Pics/*”. Any files named “Image*” will not be included since it is case-sensitive. If you want to include all files starting with “image” and not be case-sensitive, use the command “tar -cf Backupexc.tar --exclude image* --ignore-case Pics/*”.

  • --ignore-failed-read

If an error occurs because a file cannot be read, tar will exit with an error code (non-zero). If this occurs and you need the tar to complete, use the “--ignore-failed-read” option so an error code will not be generated causing tar to exit. If the command “tar -cf BackupPics.tar Pics/*” causes a read error, change the command to “tar -cf BackupPics.tar –ignore-failed-read Pics/*”

  • --index-file FILE
If you need verbose output sent to a file instead of STDOUT, use the “--index-file FILE” option. For instance, if the command “tar -cf Backup.tar --backup=numbered -g Tron.snap Tron/*” causes messages you want to look over later or print out, send verbose output to a file to look over or print. The command would be “tar -cf Backup.tar --index-file ~/BackupOfTron.txt --backup=numbered -g Tron.snap Tron/*”

  • -j, --bzip2

If you want to compress a tar file, as bzip2, and perform all the functions as one command, use the “-j” option. To archive and compress the “Pics” folder into a file called “PicsOut”, use the command “tar -cjf PicsOut.tar.bz2 Pics/*”. If you want to extract the files from the archive to a folder called “Pics2”, use the command “tar -xf PicsOut.tar.bz2 -C Pics2/”. Make sure the folder “Pics2” exists.

  • -k, --keep-old-files

When extracting files from the tar archive, do not replace an existing file. If a file is being extracted which already exists, errors will be generated. If files must be extracted from “PicsOut.tar” to the “Pics2” folder, which has some pre-existing files which cannot be overwritten, use the command “tar -xkf PicsOut.tar -C Pics2/”.

  • -K, --starting-file F

If you need only to list specific files after a certain file, use the “-K” option. For example, if files were extracted from an archive and drive space ran out, then you can list the files after the last extracted file. If a file named “PicsOut.tar” was extracting and ran out of space and quit extracting at file “image101.jpg” and you need to list the remaining files use, the command “tar -tf PicsOut.tar -K image101.jpg”.

  • --keep-newer-files

If you do not want to replace existing files which are newer than those in the archive, use the “--keep-newer-files” option. If an archive of documents were being extracted, but files which have been changed since the backup should not be replaced, the command would be “tar -xf Archive.tar –keep-newer-files Documents/”.

  • -l, --one-file-system
The “-l” option causes tar to write only to one file system and not create multi-volumes. Basically, if you archive the root folder and some mount points exist on other hard drives, the other mount points will be skipped. An example is to archive the “/” folder and any folders which are mount points from other drives will not be backed up, such as “tar -clf Fullbackup.tar /media/jarret/USBDRIVE/”.

Practice the options to be familiar with them.


  • slide.jpg
    32.9 KB · Views: 65,125
$100 Digital Ocean Credit
Get a free VM to test out Linux! Hosting Donations
Consider making a donation