J
Jarret W. Buse
Guest
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.
The “--help” option is used to display help information. No other options or commands are needed. The command is “tar --help”.
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/*”.
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/*”
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.
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/”.
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”.
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/”.
Practice the options to be familiar with them.
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
- -G, --incremental
- -h, --dereference
- --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
- --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
- -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
Practice the options to be familiar with them.