Linux Command Directory
This directory of Linux commands is from Linux in a Nutshell, 5th Edition.
Click on any of the 687 commands below to get a description and list of available options. All links in the command summaries point to the online version of the book on Safari Bookshelf.
Buy it now, or read it online on Safari Bookshelf.
tar
tar [options] [tarfile] [other-files]
Copy files to or restore files from an archive medium. If any files are directories, tar acts on the entire subtree. Options need not be preceded by - (though they may be). The exception to this rule is when you are using a long-style option (such as --modification-time). In that case, the exact syntax is:
tar--long-option -function-options files
For example:
tar --modification-time -xvf tarfile.tar
Function options
You must use exactly one of these, and it must come before any other options:
Create a new archive.
Compare the files stored in tarfile with other-files. Report any differences: missing files, different sizes, different file attributes (such as permissions or modification time).
Delete from the archive. This option cannot be used with magnetic tape.
Append other-files to the end of an existing archive.
Print the names of other-files if they are stored on the archive (if other-files are not specified, print names of all files).
Add files if not in the archive or if modified.
Extract other-files from an archive (if other-files are not specified, extract all files).
Concatenate a second tar file to the end of the first.
Options
Set drive (0-7) and storage density (l, m, or h, corresponding to low, medium, or high). Not available in all versions of tar.
Exclude patterns must match the start of the filename (the default).
Preserve original access time on extracted files.
Set block size to n × 512 bytes.
Back up files rather than deleting them. If no backup type is specified, a simple backup is made with ~ as the suffix. (See also --suffix.) The possible values of type are:
t, numbered Make numbered backups.
nil, existing Make numbered backups if there are already numbered backups; otherwise make simple backups.
never, simple Always make simple backups.
List directory names encountered.
Remove files matching pattern from any list of files.
Store files in or extract files from archive file. Note that file may take the form hostname:filename.
Interpret filenames in the form hostname:filename as local files.
Create new-style incremental backup.
Use group as the group for files added to the archive.
Dereference symbolic links, and archive the files they point to rather than the symbolic link.
Print help message and exit.
Ignore zero-sized blocks (i.e., EOFs).
Ignore case when excluding files.
Ignore unreadable files to be archived. Default behavior is to exit when encountering these.
Compress files with bzip2 before archiving them, or uncompress them with bunzip2 before extracting them.
Do not archive files from other filesystems.
When extracting files, do not overwrite files with similar names. Instead, print an error message.
Do not restore file modification times; update them to the time of extraction.
Use permissions when adding files to an archive. The permissions are specified the same way as for the chmod command.
Add only files whose contents have changed since date to the archive.
Exclude patterns may match anything following a slash.
Do not ignore case when excluding files.
Do not extract permissions information when extracting files from the archive. This is the default for users, and therefore affects only the superuser.
Do not move recursively through directories.
When extracting, create files with yourself as owner.
Don't use wildcards when excluding files; treat patterns as strings.
Wildcards do not match / when excluding files.
Allow filenames to be null-terminated with -T. Override -C.
Use the numeric owner and group IDs rather than the names.
Create old-style archive in Unix V7 rather than ANSI format.
Overwrite existing files and directory metadata when extracting from archive.
Overwrite existing directory metadata when extracting from archive.
Set owner as the owner of extracted files instead of the original owner. owner is first assumed to be a username, then, if there is no match, a numeric user ID.
Keep permissions of extracted files the same as the originals.
Create a POSIX-compliant archive.
Equivalent to invoking both the -p and -s options.
Treat each record as having size bytes, where size is a multiple of 512.
Move recursively through directories.
Remove existing directory hierarchies before extracting directories with the same name.
Remove originals after inclusion in archive.
Do not connect to remote host with rsh; instead, use command.
When extracting, sort filenames to correspond to the order in the archive.
When extracting, create files with the same ownership as the originals.
List directories being omitted when operating on an archive.
Use suffix instead of the default ~ when creating a backup file.
Print byte totals.
Compress archived files with program, or uncompress extracted files with program.
Verbose. Print filenames as they are added or extracted.
Print version information and exit.
Use/update the volume number in file.
Wait for user confirmation (y) before taking any actions.
Use wildcards when excluding files.
Wildcards match / when excluding files.
Compress files with gzip before archiving them, or uncompress them with gunzip before extracting them.
Reblock while reading; used for reading from 4.2BSD pipes.
cd to directory before beginning tar operation.
Implies -M (multiple archive files). Run script at the end of each file.
Create old-style incremental backup.
Begin tar operation at file in archive.
Write a maximum of length × 1024 bytes to each tape.
Expect archive to be multivolume. With -c, create such an archive.
Ignore files older than date.
Print extracted files to standard output.
Do not remove initial slashes (/) from input filenames.
Display archive's block number in messages.
Treat sparse files more efficiently when adding to archive.
Consult file for files to extract or create.
Remove each existing file from the filesystem before extracting from the archive.
Name this volume name.
Check archive for corruption after creation.
Consult file for list of files to exclude.
Compress files with compress before archiving them, or uncompress them with uncompress before extracting them.
Examples
Create an archive of /bin and /usr/bin (c), show the command working (v), and store on the tape in /dev/rmt0:
tar cvf /dev/rmt0 /bin /usr/bin
List the tape's contents in a format like ls -l:
tar tvf /dev/rmt0
Extract the /bin directory:
tar xvf /dev/rmt0 /bin
Create an archive of the current directory and store it in a file backup.tar:
tar cvf - `find . -print` > backup.tar
(The - tells tar to store the archive on standard output, which is then redirected.)
Filter an archive through gzip, extracting the contents but leaving the original file compressed:
tar xvfz chapters.tar.gz




