Applications 27 – Uncommon Options of tar Part 3

J

Jarret W. Buse

Guest
Applications 27 – Uncommon Options of tar Part 3

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.

  • -L, --tape-length N
If the files are being written to a tape (uncommon), specify the tape length by the value of N*1024 bytes. For example, to specify the length as 100 * 1024 bytes, the options would be “--tape-length 100”.

  • -m, --touch, --modification-time

If the modification time stored in the tar should not be extracted as part of the file, use the “-m” option. For example, you want to extract files from the “Pics.tar” archive without the modification times to the current folder. The command would be “tar -xmf Pics.tar”.

  • -M, --multi-volume
If an archive is stored on multiple volumes and you wish to create, list or extract the files, use the “-M” option. If you need to create an archive of the files in the “data” folder (named “MultipleOut.tar”) which requires multiple media disks, use the command “tar -cMf MultipleOut.tar data/*”.

  • --mode PERMISSIONS
Some files being archived need to have permissions changed. To change permissions of these files, use the “--mode PERMISSIONS” option. To apply Full Permissions to all users and groups, the PERMISSION would be “777”. The command would then be “tar -cf Out.tar --mode 777 data/*”.

  • -N, --after-date DATE, --newer DATE
To only archive changed files on or after a specified date, use the “-N” option. For example, to archive files in the “Data” folder which has been changed on or after “07/07/15” to an archive called “Date.tar”, the command would be “tar -cf Date.tar -N 07/07/15 Data/*”.

  • --newer-mtime DATE
To only archive files modified on or after a specified date, use the “-newer-mtime” option. For example, to archive files in the “Data” folder which has been modified on or after “07/01/15” to an archive called “ModifiedDate.tar”, the command would be “tar -cf ModifiedDate.tar --newer-mtime 07/01/15 Data/*”.

  • --no-ignore-case

To use the “--exclude” options and make the exclusion case-sensitive, use the “no-ignore-case” options with it. 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* --no-ignore-case Pics/*”. Any files named “Image*” will not be included since it is case-sensitive.

  • --no-recursion

To archive files within a specified folder and not include subfolders and file therein, use the “--no-recursion” option. So, to archive files in “Folder1” and not include subfolder “Folder2”, then use this option. The command to archive “Folder1” only into a file named “Folder1.tar”, use the command “tar -cf Folder1.tar --no-recursion Folder1/*”.

  • --no-same-permissions
When extracting files, the permissions of the folder for current user can be used instead of those which have been stored in the archive. To extract files from the archive “Folder1.tar” to the current folder and the permissions of the current user, the command would be “tar -xf Folder1.tar –no-same-permissions *”.

  • --no-wildcards

The “--no-wildcards” options is used with the “--exclude” option so wildcards are not used.

  • --no-wildcards-match-slash

When using “--exclude”, the wildcards to match a slash (/).

  • --null

The “--null option allows for the reading of null terminated names when using the option “--files-from”. The “--files-from” is a file containing a list of files to archive. The filenames can be null terminated. To create a tar called “File1.tar” from the files listed in the text file “filelist.txt”, the command would be “tar -cf File1.tar -T filelist.txt --null”.

  • --numeric-owner
When an archive is created, owner permissions are set by name. If the owner permissions need to be by owner ID instead of name, use the “--numeric-owner” option. This adds a level of security for anyone who can access the tar and retrieve usernames from the archive. To archive all files from the “Pics” folder to a file named “Backup.tar”, but storing the owner ID, use the command “tar -cf Backup.tar --numeric-owner Pics/*”.

  • --old-archive, --portability

To store the tar in a UNIX Version 7 format, use the “--old-archive” option. If you need to create a UNIX v7 archive, of the files in the “data” folder, named “Old.tar” use the command “tar -cf Old.tar --old-archive data/*”.

  • --no-same-owner
When extracting a tar file, do not restore the same ownership. To extract a file named “Archive.tar” to the “Archive” folder without the same ownership, use the following command “tar -xf Archive.tar –no-same-owner -C Archive”.

  • -O, --to-stdout

All files extracted will be sent to STDOUT. The process is useful for piping. If multiple files exist, they will be joined into one file. For instance, if you have an archive of text files, “Text.tar”, and wish to join them to one large file called “Main.txt” joined in alphabetical order, use the “-O” option. The command would be “tar -xOf Text.tar > Main.txt”.

As with the other tar options, practice them to be sure you understand them completely.
 

Attachments

  • slide.jpg
    slide.jpg
    32.9 KB · Views: 99,643

Members online


Top