Index:
[(1)addftinfo(1)
addr2line(1)
afmtodit(1)
alias(1)
alloc(1)
apply(1)
apropos(1)
ar(1)
as(1)
asa(1)
at(1)
atq(1)
atrm(1)
awk(1)
b64decode(1)
b64encode(1)
basename(1)
batch(1)
bc(1)
bdes(1)
bg(1)
biff(1)
bind(1)
bindkey(1)
brandelf(1)
break(1)
breaksw(1)
bsdtar(1)
bsnmpd(1)
bthost(1)
btsockstat(1)
builtin(1)
builtins(1)
bunzip2(1)
byacc(1)
bzcat(1)
bzegrep(1)
bzfgrep(1)
bzgrep(1)
bzip2(1)
c++(1)
c89(1)
c99(1)
cal(1)
calendar(1)
cap_mkdb(1)
case(1)
cat(1)
catman(1)
cc(1)
cd(1)
cdcontrol(1)
chdir(1)
checknr(1)
chflags(1)
chfn(1)
chgrp(1)
chio(1)
chkey(1)
chmod(1)
chpass(1)
chsh(1)
ci(1)
ckdist(1)
cksum(1)
clear(1)
cmp(1)
co(1)
col(1)
colcrt(1)
colldef(1)
colrm(1)
column(1)
comm(1)
command(1)
compile_et(1)
complete(1)
compress(1)
continue(1)
cp(1)
cpio(1)
cpp(1)
crontab(1)
crunchgen(1)
crunchide(1)
crypt(1)
csh(1)
csplit(1)
ctags(1)
ctm(1)
ctm_dequeue(1)
ctm_rmail(1)
ctm_smail(1)
cu(1)
cursor(1)
cut(1)
cvs(1)
date(1)
dc(1)
dd(1)
default(1)
df(1)
dialog(1)
diff(1)
diff3(1)
dig(1)
dirname(1)
dirs(1)
do(1)
domainname(1)
done(1)
dtmfdecode(1)
du(1)
echo(1)
echotc(1)
ed(1)
edit(1)
ee(1)
egrep(1)
elfdump(1)
elif(1)
else(1)
end(1)
endif(1)
endsw(1)
enigma(1)
env(1)
eqn(1)
esac(1)
eval(1)
ex(1)
exec(1)
exit(1)
expand(1)
export(1)
expr(1)
f77(1)
false(1)
fc(1)
fdformat(1)
fdread(1)
fdwrite(1)
fetch(1)
fg(1)
fgrep(1)
fi(1)
file(1)
file2c(1)
filetest(1)
find(1)
finger(1)
flex++(1)
flex(1)
fmt(1)
fold(1)
fontedit(1)
for(1)
foreach(1)
from(1)
fstat(1)
fsync(1)
ftp(1)
g++(1)
g711conv(1)
gate-ftp(1)
gcc(1)
gcore(1)
gcov(1)
gdb(1)
gencat(1)
gensnmptree(1)
getNAME(1)
getconf(1)
getfacl(1)
getopt(1)
getopts(1)
glob(1)
goto(1)
gperf(1)
gprof(1)
grep(1)
grn(1)
grodvi(1)
groff(1)
grog(1)
grolbp(1)
grolj4(1)
grops(1)
grotty(1)
groups(1)
gtar(1)
gunzip(1)
gzcat(1)
gzexe(1)
gzip(1)
hash(1)
hashstat(1)
hd(1)
head(1)
hesinfo(1)
hexdump(1)
history(1)
host(1)
hostname(1)
hpftodit(1)
hup(1)
id(1)
ident(1)
idprio(1)
if(1)
indent(1)
indxbib(1)
info(1)
install-info(1)
install(1)
intro(1)
introduction(1)
ipcrm(1)
ipcs(1)
ipftest(1)
ipnat(1)
ipresend(1)
ipsend(1)
iptest(1)
jobid(1)
jobs(1)
join(1)
jot(1)
kbdcontrol(1)
kbdmap(1)
kcon(1)
kdestroy(1)
kdump(1)
kenv(1)
keylogin(1)
keylogout(1)
kgdb(1)
kill(1)
killall(1)
kinit(1)
klist(1)
kpasswd(1)
krb5-config(1)
ktrace(1)
lam(1)
last(1)
lastcomm(1)
ld-elf.so.1(1)
ld(1)
ld(1)
ldd(1)
leave(1)
less(1)
lesskey(1)
lex++(1)
lex(1)
limit(1)
limits(1)
link(1)
lint(1)
lkbib(1)
ln(1)
loadfont(1)
locale(1)
locate(1)
lock(1)
lockf(1)
log(1)
logger(1)
login(1)
logins(1)
logname(1)
logout(1)
look(1)
lookbib(1)
lorder(1)
lp(1)
lpq(1)
lpr(1)
lprm(1)
lptest(1)
ls-F(1)
ls(1)
lsvfs(1)
m4(1)
mail(1)
mailq(1)
mailx(1)
make(1)
makeinfo(1)
makewhatis(1)
man(1)
manpath(1)
md5(1)
merge(1)
mesg(1)
minigzip(1)
mkdep(1)
mkdir(1)
mkfifo(1)
mklocale(1)
mkstr(1)
mktemp(1)
mmroff(1)
more(1)
mptable(1)
msgs(1)
mt(1)
mv(1)
nawk(1)
nc(1)
ncal(1)
ncplist(1)
ncplogin(1)
ncplogout(1)
neqn(1)
netstat(1)
newaliases(1)
newgrp(1)
nex(1)
nfsstat(1)
nice(1)
nl(1)
nm(1)
nohup(1)
notify(1)
nroff(1)
nslookup(1)
nvi(1)
nview(1)
objcopy(1)
objdump(1)
objformat(1)
od(1)
omshell(1)
onintr(1)
opieinfo(1)
opiekey(1)
opiepasswd(1)
otp-md4(1)
otp-md5(1)
otp-sha(1)
pagesize(1)
passwd(1)
paste(1)
patch(1)
pathchk(1)
pawd(1)
pax(1)
pfbtops(1)
pftp(1)
pgrep(1)
pic(1)
pkg_add(1)
pkg_check(1)
pkg_create(1)
pkg_delete(1)
pkg_info(1)
pkg_sign(1)
pkg_version(1)
pkill(1)
popd(1)
pr(1)
printenv(1)
printf(1)
ps(1)
psroff(1)
pushd(1)
pwd(1)
quota(1)
ranlib(1)
rcp(1)
rcs(1)
rcsclean(1)
rcsdiff(1)
rcsfreeze(1)
rcsintro(1)
rcsmerge(1)
read(1)
readelf(1)
readlink(1)
readonly(1)
realpath(1)
red(1)
ree(1)
refer(1)
rehash(1)
repeat(1)
reset(1)
rev(1)
rfcomm_sppd(1)
rlog(1)
rlogin(1)
rm(1)
rmd160(1)
rmdir(1)
rpcgen(1)
rs(1)
rsh(1)
rtld(1)
rtprio(1)
rup(1)
ruptime(1)
rusers(1)
rwall(1)
rwho(1)
sched(1)
scon(1)
scp(1)
script(1)
sdiff(1)
sed(1)
send-pr(1)
sendbug(1)
set(1)
setenv(1)
setfacl(1)
settc(1)
setty(1)
setvar(1)
sftp(1)
sh(1)
sha1(1)
shar(1)
shift(1)
size(1)
sleep(1)
slogin(1)
smbutil(1)
sockstat(1)
soelim(1)
sort(1)
source(1)
split(1)
sscop(1)
ssh-add(1)
ssh-agent(1)
ssh-keygen(1)
ssh-keyscan(1)
ssh(1)
startslip(1)
stat(1)
stop(1)
strings(1)
strip(1)
stty(1)
su(1)
sum(1)
suspend(1)
switch(1)
systat(1)
tabs(1)
tail(1)
talk(1)
tar(1)
tbl(1)
tcopy(1)
tcpdump(1)
tcpslice(1)
tcsh(1)
tee(1)
telltc(1)
telnet(1)
test(1)
texindex(1)
tfmtodit(1)
tftp(1)
then(1)
time(1)
tip(1)
top(1)
touch(1)
tput(1)
tr(1)
trace(1)
trap(1)
troff(1)
true(1)
truncate(1)
truss(1)
tset(1)
tsort(1)
tty(1)
type(1)
ul(1)
ulimit(1)
umask(1)
unalias(1)
uname(1)
uncomplete(1)
uncompress(1)
unexpand(1)
unhash(1)
unifdef(1)
unifdefall(1)
uniq(1)
units(1)
unlimit(1)
unlink(1)
unset(1)
unsetenv(1)
until(1)
unvis(1)
uptime(1)
usbhidaction(1)
usbhidctl(1)
users(1)
uudecode(1)
uuencode(1)
uuidgen(1)
vacation(1)
vgrind(1)
vi(1)
vidcontrol(1)
vidfont(1)
view(1)
vis(1)
vt220keys(1)
vttest(1)
w(1)
wait(1)
wall(1)
wc(1)
what(1)
whatis(1)
where(1)
whereis(1)
which(1)
while(1)
who(1)
whoami(1)
whois(1)
window(1)
write(1)
xargs(1)
xstr(1)
yacc(1)
yes(1)
ypcat(1)
ypchfn(1)
ypchpass(1)
ypchsh(1)
ypmatch(1)
yppasswd(1)
ypwhich(1)
yyfix(1)
zcat(1)
zcmp(1)
zdiff(1)
zegrep(1)
zfgrep(1)
zforce(1)
zgrep(1)
zmore(1)
znew(1)
bsdtar(1)
NAME
tar -- manipulate tape archives
SYNOPSIS
tar [bundled-flags <args>] [<file> | <pattern> ...] tar {-c} [options] [files | directories] tar {-r | -u} -f archive-file [options] [files | directories] tar {-t | -x} [options] [patterns]
DESCRIPTION
tar creates and manipulates streaming archive files. The first synopsis form shows a ``bundled'' option word. This usage is provided for compatibility with historical implementations. See COMPATI- BILITY below for details. The other synopsis forms show the preferred usage. The first option to tar is a mode indicator from the following list: -c Create a new archive containing the specified items. -r Like -c, but new entries are appended to the archive. Note that this only works on uncompressed archives stored in regular files. The -f option is required. -t List archive contents to stdout. -u Like -r, but new entries are added only if they have a modifica- tion date newer than the corresponding entry in the archive. Note that this only works on uncompressed archives stored in reg- ular files. The -f option is required. -x Extract to disk from the archive. If a file with the same name appears more than once in the archive, each copy will be extracted, with later copies overwriting (replacing) earlier copies. In -c, -r, or -u mode, each specified file or directory is added to the archive in the order specified on the command line. By default, the con- tents of each directory are also archived. In extract or list mode, the entire command line is read and parsed before the archive is opened. The pathnames or patterns on the command line indicate which items in the archive should be processed. Patterns are shell-style globbing patterns as documented in XXXX.
OPTIONS
Unless specifically stated otherwise, options are applicable in all oper- ating modes. @archive (c and r mode only) The specified archive is opened and the entries in it will be appended to the current archive. As a sim- ple example, tar -c -f - newfile @original.tar writes a new archive to standard output containing a file newfile and all of the entries from original.tar. In contrast, tar -c -f - newfile original.tar creates a new archive with only two entries. Similarly, tar -czf - --format pax @- reads an archive from standard input (whose format will be deter- mined automatically) and converts it into a gzip-compressed pax- -C directory In c and r mode, this changes the directory before adding the following files. In x mode, change directories after opening the archive but before extracting entries from the archive. --check-links (-W check-links) (c and r modes only) Issue a warning message unless all links to each file are archived. --exclude pattern (-W exclude=pattern) Do not process files or directories that match the specified pat- tern. Note that exclusions take precedence over patterns or filenames specified on the command line. --format format (-W format=format) (c mode only) Use the specified format for the created archive. Supported formats include ``cpio'', ``pax'', ``shar'', and ``ustar''. Other formats may also be supported; see libarchive-formats(5) for more information about currently-sup- ported formats. -f file Read the archive from or write the archive to the specified file. The filename can be - for standard input or standard output. If not specified, the default tape device will be used. (On FreeBSD, the default tape device is /dev/sa0.) --fast-read (-W fast-read) (x and t mode only) Extract or list only the first archive entry that matches each pattern or filename operand. Exit as soon as each specified pattern or filename has been matched. By default, the archive is always read to the very end, since there can be multiple entries with the same name and, by convention, later entries overwrite earlier entries. This option is provided as a performance optimization. -H (c and r mode only) Symbolic links named on the command line will be followed; the target of the link will be archived, not the link itself. -h (c and r mode only) Synonym for -L. --include pattern (-W include=pattern) Process only files or directories that match the specified pat- tern. Note that exclusions specified with --exclude take prece- dence over inclusions. If no inclusions are explicitly speci- fied, all entries are processed by default. The --include option is especially useful when filtering archives. For example, the command tar -c -f new.tar --include='*foo*' @old.tgz creates a new archive new.tar containing only the entries from old.tgz containing the string `foo'. -j (c mode only) Compress the resulting archive with bzip2(1). In extract or list modes, this option is ignored. Note that, unlike other tar implementations, this implementation recognizes bzip2 compression automatically when reading archives. -l If POSIXLY_CORRECT is specified in the environment, this is a synonym for the --check-links option. Otherwise, an error will be displayed. Users who desire behavior compatible with GNU tar should use the --one-file-system option instead. -m (x mode only) Do not extract modification time. By default, the modification time is set to the time stored in the archive. -n (c, r, u modes only) Do not recursively archive the contents of directories. --nodump (-W nodump) (c and r modes only) Honor the nodump file flag by skipping this file. -O (x, t modes only) In extract (-x) mode, files will be written to standard out rather than being extracted to disk. In list (-t) mode, the file listing will be written to stderr rather than the usual stdout. -o (x mode only) Use the user and group of the user running the pro- gram rather than those specified in the archive. Note that this has no significance unless -p is specified, and the program is being run by the root user. In this case, the file modes and flags from the archive will be restored, but ACLs or owner infor- mation in the archive will be discarded. -P Preserve pathnames. By default, absolute pathnames (those that begin with a / character) have the leading slash removed both when creating archives and extracting from them. Also, tar will refuse to extract archive entries whose pathnames contain .. or whose target directory would be altered by a symlink. This option suppresses these behaviors. -p (x mode only) Preserve file permissions. Attempt to restore the full permissions, including owner, file modes, file flags and ACLs, if available, for each item extracted from the archive. By default, newly-created files are owned by the user running tar, the file mode is restored for newly-created regular files, and all other types of entries receive default permissions. If tar is being run by root, the default is to restore the owner unless the -o option is also specified. -T filename (c mode only) Read names to be archived from filename. Names are terminated by newlines. The special name ``-C'' will cause the current directory to be changed to the directory specified on the following line. -U (x mode only) Unlink files before creating them. Without this option, tar overwrites existing files, which preserves existing hardlinks. With this option, existing hardlinks will be broken, as will any symlink that would affect the location of an extracted file. -v Produce verbose output. In create and extract modes, tar will list each file name as it is read from or written to the archive. -w Ask for confirmation for every action. -X filename Read a list of exclusion patterns from the specified file. See --exclude for more information about the handling of exclusions. -y (c mode only) Compress the resulting archive with bzip2(1). In extract or list modes, this option is ignored. Note that, unlike other tar implementations, this implementation recognizes bzip2 compression automatically when reading archives. -z (c mode only) Compress the resulting archive with gzip(1). In extract or list modes, this option is ignored. Note that, unlike other tar implementations, this implementation recognizes gzip compression automatically when reading archives.
ENVIRONMENT
The following environment variables affect the execution of tar: LANG The locale to use. See environ(7) for more information. POSIXLY_CORRECT If this environment variable is defined, the -l option will be interpreted in accordance with ISO/IEC 9945-1:1996 (``POSIX.1''). TAPE The default tape device. The -f option overrides this. TZ The timezone to use when displaying dates. See environ(7) for more information.
FILES
/dev/sa0 The default tape device, if not overridden by the TAPE envi- ronment variable or the -f option.
EXIT STATUS
The tar utility exits 0 on success, and >0 if an error occurs.
EXAMPLES
The following creates a new archive called file.tar that contains two files source.c and source.h: tar -czf file.tar source.c source.h To view a detailed table of contents for this archive: tar -tvf file.tar To extract all entries from the archive on the default tape drive: tar -x In create mode, the list of files and directories to be archived can also include directory change instructions of the form -Cfoo/baz and archive inclusions of the form @archive-file. For example, the command line tar -c -f new.tar foo1 @old.tgz -C/tmp foo2 will create a new archive new.tar. tar will read the file foo1 from the current directory and add it to the output archive. It will then read each entry from old.tgz and add those entries to the output archive. Finally, it will switch to the /tmp directory and add foo2 to the output tar tbf 32 file.tar specifies three flags t, b, and f. The b and f flags both require argu- ments, so there must be two additional items on the command line. The 32 is the argument to the b flag, and file.tar is the argument to the f flag. The mode options c, r, t, u, and x and the options b, f, l, m, o, v, and w comply with SUSv2. For maximum portability, scripts that invoke tar should use the bundled- argument format above, should limit themselves to the c, t, and x modes, and the b, f, m, v, and w options. On systems that support getopt_long(), additional long options are avail- able to improve compatibility with other tar implementations.
SECURITY
Certain security issues are common to many archiving programs, including tar. In particular, carefully-crafted archives can request that tar extract files to locations outside of the target directory. This can potentially be used to cause unwitting users to overwrite files they did not intend to overwrite. If the archive is being extracted by the supe- ruser, any file on the system can potentially be overwritten. There are three ways this can happen. Although tar has mechanisms to protect against each one, savvy users should be aware of the implications: o Archive entries can have absolute pathnames. By default, tar removes the leading / character from filenames before restoring them to guard against this problem. o Archive entries can have pathnames that include .. components. By default, tar will not extract files containing .. components in their pathname. o Archive entries can exploit symbolic links to restore files to other directories. An archive can restore a symbolic link to another directory, then use that link to restore a file into that directory. To guard against this, tar checks each extracted path for symlinks. If the final path element is a symlink, it will be removed and replaced with the archive entry. If -U is specified, any intermediate symlink will also be unconditionally removed. If neither -U nor -P is specified, tar will refuse to extract the entry. To protect yourself, you should be wary of any archives that come from untrusted sources. You should examine the contents of an archive with tar -tf filename before extraction. You should use the -k option to ensure that tar will not overwrite any existing files or the -U option to remove any pre- existing files. You should generally not extract archives while running with super-user privileges. Note that the -P option to tar disables the security checks above and allows you to extract an archive while preserv- ing any absolute pathnames, .. components, or symlinks to other directo- ries.
SEE ALSO
bzip2(1), cpio(1), gzip(1), mt(1), pax(1), shar(1), libarchive(3), libarchive-formats(5), tar(5) The ustar and pax interchange file formats are defined by IEEE Std 1003.1-2001 (``POSIX.1'') for the pax command.
HISTORY
A tar command appeared in Seventh Edition Unix. There have been numerous other implementations, many of which extended the file format. John Gilmore's pdtar public-domain implementation (circa November, 1987) was quite influential, and formed the basis of GNU tar. GNU tar was included as the standard system tar in FreeBSD beginning with FreeBSD 1.0. This is a complete re-implementation based on the libarchive(3) library.
BUGS
POSIX and GNU violently disagree about the meaning of the -l option. Because of the potential for disaster if someone expects one behavior and gets the other, the -l option is deliberately broken in this implementa- tion. The -C dir option may differ from historic implementations. All archive output is written in correctly-sized blocks, even if the out- put is being compressed. Whether or not the last output block is padded to a full block size varies depending on the format and the output device. For tar and cpio formats, the last block of output is padded to a full block size if the output is being written to standard output or to a character or block device such as a tape drive. If the output is being written to a regular file, the last block will not be padded. Many com- pressors, including gzip(1) and bzip2(1), complain about the null padding when decompressing an archive created by tar, although they still extract it correctly. The compression and decompression is implemented internally, so there may be insignificant differences between the compressed output generated by tar -czf - file and that generated by tar -cf - file | gzip The default should be to read and write archives to the standard I/O paths, but tradition (and POSIX) dictates otherwise. The r and u modes require that the archive be uncompressed and located in a regular file on disk. Other archives can be modified using c mode with the @archive-file extension. To archive a file called @foo or -foo you must specify it as ./@foo or ./-foo, respectively. In create mode, a leading ./ is always removed. A leading / is stripped unless the -P option is specified. There needs to be better support for file selection on both create and extract. There is not yet any support for multi-volume archives or for archiving sparse files. Converting between dissimilar archive formats (such as tar and cpio) using the @- convention can cause hard link information to be lost.
SPONSORED LINKS
Man(1) output converted with man2html , sed , awk