BSDTAR(1)
π BSDTAR(1): manipulate tape archives π
hey bestie, welcome to bsdtar from the General Commands Manual, section 1 β the tool that manipulates tape archives and honestly has main character energy in the archive world. no cap.
π NAME π
bsdtar β manipulate tape archives
β¨ SYNOPSIS β¨
bsdtar [bundled-flags β¨argsβ©] [β¨fileβ© | β¨patternβ© ...]
bsdtar {-c} [options] [files | directories]
bsdtar {-r | -u} -f archive-file [options] [files | directories]
bsdtar {-t | -x} [options] [patterns]
πΈ DESCRIPTION πΈ
okay so bsdtar creates and manipulates streaming archive files. this implementation can extract from tar, pax, cpio, zip, jar, ar, xar, rar, rpm, 7-zip, and ISO 9660 cdrom images β and it can create tar, pax, cpio, ar, zip, 7-zip, and shar archives. versatile icon behavior, fr fr.
The first synopsis form shows a βbundledβ option word. This usage is provided for compatibility with historical implementations. See βCOMPATIBILITYβ below for details. iykyk, old-school compatibility moment.
The other synopsis forms show the preferred usage. The first option to bsdtar is a mode indicator from the following list:
-cβ Create a new archive containing the specified items. The long option form is--create. β¨-rβ Like-c, but new entries are appended to the archive. Note that this only works on uncompressed archives stored in regular files. The-foption is required. The long option form is--append.-tβ List archive contents to stdout. The long option form is--list. π-uβ Like-r, but new entries are added only if they have a modification date newer than the corresponding entry in the archive. Note that this only works on uncompressed archives stored in regular files. The-foption is required. The long form is--update.-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. The long option form is--extract. heads up bestie: later copies win.
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 contents of each directory are also archived. order matters, and directories bring their whole friend group.
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 tcsh(1). globbing girlies rise.
π OPTIONS π
Unless specifically stated otherwise, options are applicable in all operating modes.
@archiveβ (candrmodes only) The specified archive is opened and the entries in it will be appended to the current archive. As a simple example,
bsdtar -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,
bsdtar -c -f - newfile original.tar
creates a new archive with only two entries. Similarly,
bsdtar -czf - --format pax @-
reads an archive from standard input (whose format will be determined automatically) and converts it into a gzip-compressed pax-format archive on stdout. In this way, bsdtar can be used to convert archives from one format to another. format glow-up, literally.
-a,--auto-compressβ (cmode only) Use the archive suffix to decide a set of the format and the compressions. As a simple example,
bsdtar -a -cf archive.tgz source.c source.h
creates a new archive with restricted pax format and gzip compression,
bsdtar -a -cf archive.tar.bz2.uu source.c source.h
creates a new archive with restricted pax format and bzip2 compression and uuencode compression,
bsdtar -a -cf archive.zip source.c source.h
creates a new archive with zip format,
bsdtar -a -jcf archive.tgz source.c source.h
ignores the β-jβ option, and creates a new archive with restricted pax format and gzip compression,
bsdtar -a -jcf archive.xxx source.c source.h
if it is unknown suffix or no suffix, creates a new archive with restricted pax format and bzip2 compression. suffix detective era.
--aclsβ (c,r,u,xmodes only) Archive or extract POSIX.1e or NFSv4 ACLs. This is the reverse of--no-aclsand the default behavior inc,r, andumodes (except on Mac OS X) or ifbsdtaris run inxmode as root. On Mac OS X this option translates extended ACLs to NFSv4 ACLs. To store extended ACLs the--mac-metadataoption is preferred. ACL lore, but make it cute.-B,--read-full-blocksβ Ignored for compatibility with othertar(1)implementations. just vibing here, no actual job.-b blocksize,--block-size blocksizeβ Specify the block size, in512-byte records, for tape drive I/O. As a rule, this argument is only needed when reading from or writing to tape drives, and usually not even then as the default block size of20 records (10240 bytes)is very common.-C directory,--cd directory,--directory directoryβ Incandrmode, this changes the directory before adding the following files. Inxmode, change directories after opening the archive but before extracting entries from the archive. directory hop, but make it timed.--chrootβ (xmode only)chroot()to the current directory after processing any-Coptions and before extracting any files.--clamp-mtimeβ (use with--mtime) Only set the modification time if the file is newer than the date specified in--mtime.--clear-nochange-fflagsβ (xmode only) Before removing file system objects to replace them, clear platform-specific file attributes or file flags that might prevent removal. cleanup before the takeover.--exclude patternβ Do not process files or directories that match the specified pattern. Note that exclusions take precedence over patterns or filenames specified on the command line. exclusions said βnot todayβ and they mean it.--exclude-vcsβ Do not process files or directories internally used by the version control systems βArchβ, βBazaarβ, βCVSβ, βDarcsβ, βMercurialβ, βRCSβ, βSCCSβ, βSVNβ and βgitβ. version control clutter, begone.--fflagsβ (c,r,u,xmodes only) Archive or extract platform-specific file attributes or file flags. This is the reverse of--no-fflagsand the default behavior inc,r, andumodes or ifbsdtaris run inxmode as root.--format formatβ (c,r,umode only) Use the specified format for the created archive. Supported formats include βcpioβ, βpaxβ, βsharβ, and βustarβ. Other formats may also be supported; seelibarchive-formats(5)for more information about currently-supported formats. Inrandumodes, when extending an existing archive, the format specified here must be compatible with the format of the existing archive on disk. match the format or itβs awkward.-f file,--file fileβ Read the archive from or write the archive to the specified file. The filename can be-for standard input or standard output. The default varies by system; on FreeBSD, the default is/dev/sa0; on Linux, the default is/dev/st0. yes,-is the stdio bestie.--gid idβ Use the provided group id number. On extract, this overrides the group id in the archive; the group name in the archive will be ignored. On create, this overrides the group id read from disk; if--gnameis not also specified, the group name will be set to match the group id.--gname nameβ Use the provided group name. On extract, this overrides the group name in the archive; if the provided group name does not exist on the system, the group id (from the archive or from the--gidoption) will be used instead. On create, this sets the group name that will be stored in the archive; the name will not be verified against the system group database. name says one thing, system may say another.--group name[:gid]β Use the provided group, ifgidis not provided,namecan be either a group name or numeric id. See the--gnameoption for details.-Hβ (candrmodes only) Symbolic links named on the command line will be followed; the target of the link will be archived, not the link itself.-hβ (candrmodes only) Synonym for-L.-Iβ Synonym for-T.--helpβ Show usage. when in doubt, ask for help bestie.--hfsCompressionβ (xmode only) Mac OS X specific (v10.6or later). Compress extracted regular files with HFS+ compression.--ignore-zerosβ An alias of--options read_concatenated_archivesfor compatibility with GNU tar.--include patternβ Process only files or directories that match the specified pattern. Note that exclusions specified with--excludetake precedence over inclusions. If no inclusions are explicitly specified, all entries are processed by default. The--includeoption is especially useful when filtering archives. For example, the command
bsdtar -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β. filtering archives? slay.
-J,--xzβ (cmode only) Compress the resulting archive withxz(1). In extract or list modes, this option is ignored. Note that thistarimplementation recognizes XZ compression automatically when reading archives. xz said compress, but only in create mode.-j,--bzip,--bzip2,--bunzip2β (cmode only) Compress the resulting archive withbzip2(1). In extract or list modes, this option is ignored. Note that thistarimplementation recognizes bzip2 compression automatically when reading archives. bzip2 bestie, but read mode is unbothered.-k,--keep-old-filesβ (xmode only) Do not overwrite existing files. In particular, if a file appears more than once in an archive, later copies will not overwrite earlier copies. protect the originals, periodt.--keep-newer-filesβ (xmode only) Do not overwrite existing files that are newer than the versions appearing in the archive being extracted.-L,--dereferenceβ (candrmodes only) All symbolic links will be followed. Normally, symbolic links are archived as such. With this option, the target of the link will be archived instead.-l,--check-linksβ (candrmodes only) Issue a warning message unless all links to each file are archived. link check, because missing links are not the vibe.--lrzipβ c mode only, bestie. Squishes your archive withlrzip(1)before it goes out into the world. In extract or list modes this option just gets ignored, like your ex's texts. And ngl, this tar implementation clocks lrzip compression automatically when it's reading archives, so you don't gotta tell it twice π--lz4β c mode only. Compresses the archive with lz4-compatible compression before writing it. Extract or list mode? Ignored, periodt. This tar implementation recognizes lz4 compression automatically when reading archives, iykyk β¨--zstdβ c mode only. Compresses the archive with zstd-compatible compression before writing it. Extract or list modes ignore it, and this tar implementation recognizes zstd compression automatically when reading archives π¦--lzmaβ c mode only. Compresses the resulting archive with the original LZMA algorithm. Extract or list modes ignore it. > β οΈ Heads up bestie: use of this option is discouraged, and new archives should be created with--xzinstead. It's giving deprecated. LZMA compression is still recognized automatically when reading archives though π--lzopβ c mode only. Compresses the resulting archive withlzop(1). Ignored in extract or list modes. This tar implementation recognizes LZO compression automatically when reading archives, slay π-m,--modification-timeβ x mode only. Do not extract the modification time. By default the modification time gets set to the time stored in the archive, so this is you saying "leave my mtimes alone fr fr" π--mac-metadataβ c, r, u and x mode only. Mac OS X specific, okurrr. Archives or extracts extended ACLs and extended file attributes usingcopyfile(3)in AppleDouble format. This is the reverse of--no-mac-metadata, and it's the default behavior in c, r, and u modes, or ifbsdtaris run in x mode as root. Currently supported only for pax formats (including pax restricted, the default tar format forbsdtar) π--mtimedate β c, r, u modes only. Sets the modification times of added files to the date you specified. Main character energy: you decide the timestamp π-n,--norecurse,--no-recursionβ Do not operate recursively on the content of directories. One level only, no rabbit holes π--newerdate β c, r, u modes only. Only includes files and directories newer than the specified date. It compares ctime entries for this one.--newer-mtimedate β c, r, u modes only. Like--newer, except it compares mtime entries instead of ctime entries. Same vibe, different clock π--newer-thanfile β c, r, u modes only. Only includes files and directories newer than the specified file. Compares ctime entries.--newer-mtime-thanfile β c, r, u modes only. Like--newer-than, except it compares mtime entries instead of ctime entries.--nodumpβ c and r modes only. Honors the nodump file flag by skipping this file. Respect the flag, bestie π©--nopreserveHFSCompressionβ x mode only. Mac OS X specific (v10.6 or later). Do not compress extracted regular files which were compressed with HFS+ compression before being archived. By default, the regular files get compressed again with HFS+ compression π«--nullβ (use with-Ior-T) Filenames or patterns are separated by null characters, not by newlines. This is often used to read filenames output by the-print0option tofind(1). Nulls > newlines, no cap π«Ά--no-aclsβ c, r, u, x modes only. Do not archive or extract POSIX.1e or NFSv4 ACLs. This is the reverse of--acls, and it's the default behavior ifbsdtaris run as non-root in x mode (on Mac OS X, as any user in c, r, u and x modes).--no-fflagsβ c, r, u, x modes only. Do not archive or extract file attributes or file flags. This is the reverse of--fflags, and the default behavior ifbsdtaris run as non-root in x mode.--no-mac-metadataβ c, r, u and x mode only. Mac OS X specific. Do not archive or extract ACLs and extended file attributes usingcopyfile(3)in AppleDouble format. This is the reverse of--mac-metadata, and the default behavior ifbsdtaris run as non-root in x mode.--no-read-sparseβ c, r, u modes only. Do not read sparse file information from disk. This is the reverse of--read-sparse. Sparse files, we simply do not see them π--no-safe-writesβ x mode only. Do not create temporary files and userename(2)to replace the original ones. This is the reverse of--safe-writes. It's giving yolo with your data π--no-same-ownerβ x mode only. Do not extract owner and group IDs. This is the reverse of--same-owner, and the default behavior ifbsdtaris run as non-root.--no-same-permissionsβ x mode only. Do not extract full permissions (SGID, SUID, sticky bit, file attributes or file flags, extended file attributes and ACLs). This is the reverse of-p, and the default behavior ifbsdtaris run as non-root.--no-xattrsβ c, r, u, x modes only. Do not archive or extract extended file attributes. This is the reverse of--xattrs, and the default behavior ifbsdtaris run as non-root in x mode.--numeric-ownerβ This is exactly equivalent to--uname "" --gname "". On extract, it makes user and group names in the archive get ignored in favor of the numeric user and group ids. On create, it makes user and group names not get stored in the archive. Numbers only, we don't do names π’-O,--to-stdoutβ x, t modes only. In extract (-x) mode, files get written to standard out rather than extracted to disk. In list (-t) mode, the file listing gets written to stderr rather than the usual stdout. Sneaky but iconic β¨-oβ x mode. Use the user and group of the user running the program, rather than the ones specified in the archive. Ngl this has no significance unless-pis specified and the program is being run by the root user. In that case, the file modes and flags from the archive get restored, but ACLs or owner information in the archive get discarded ποΈ-oβ c, r, u mode. A synonym for--format ustar. Yes, same flag, different personality depending on mode. She contains multitudes π--olderdate β c, r, u modes only. Only includes files and directories older than the specified date. Compares ctime entries.--older-mtimedate β c, r, u modes only. Like--older, except it compares mtime entries instead of ctime entries.--older-thanfile β c, r, u modes only. Only includes files and directories older than the specified file. Compares ctime entries.--older-mtime-thanfile β c, r, u modes only. Like--older-than, except it compares mtime entries instead of ctime entries.--one-file-systemβ c, r, and u modes. Do not cross mount points. Stay in your lane, literally π§--optionsoptions β Picks optional behaviors for particular modules, bestie. The argument is a text string stuffed with comma-separated keywords and values. These get passed to the modules that handle particular formats, to control how those formats will behave. Every option has one of these forms:key=valueβ The key gets set to the specified value in every module that supports it. Modules that do not support this key just ignore it, no hard feelings.keyβ The key gets enabled in every module that supports it. This is equivalent tokey=1.!keyβ The key gets disabled in every module that supports it.module:key=value,module:key,module:!keyβ As above, but the corresponding key and value get provided only to modules whose name matches module.
The complete list of supported modules and keys for create and append modes lives in archive_write_set_options(3), and for extract and list modes in archive_read_set_options(3). Go read those if you want the full tea β
Examples of supported options:
iso9660:jolietβ Support Joliet extensions. This is enabled by default, so use!jolietoriso9660:!jolietto disable it. β¨iso9660:rockridgeβ Support Rock Ridge extensions. Also enabled by default; use!rockridgeoriso9660:!rockridgeto turn it off. π¦gzip:compression-levelβ A decimal integer from1to9specifying the gzip compression level. Pick your compression vibe. πgzip:timestampβ Store timestamp. This is enabled by default; use!timestamporgzip:!timestampto disable it. βlrzip:compression=typeβ Use type as the compression method. Supported values arebzip2,gzip,lzo(ultra fast), andzpaq(best, extremely slow). πlrzip:compression-levelβ A decimal integer from1to9specifying the lrzip compression level. πlz4:compression-levelβ A decimal integer from1to9specifying the lzop compression level. yep, it says lzop β we keep the details exactly as they are. πlz4:stream-checksumβ Enable stream checksum. This is by default; uselz4:!stream-checksumto disable it. πΈlz4:block-checksumβ Enable block checksum (disabled by default). π«Άlz4:block-sizeβ A decimal integer from4to7specifying the lz4 compression block size (7is set by default). π₯lz4:block-dependenceβ Use the previous block of the block being compressed as a compression dictionary to improve the compression ratio. smart-girl compression move. πzstd:compression-level=Nβ A decimal integer specifying the zstd compression level. Supported values depend on the library version; common values are from1to22. πzstd:threads=Nβ Specify the number of worker threads to use, or0to use as many threads as there are CPU cores in the system. βzstd:frame-per-fileβ Start a new compression frame at the beginning of each file in the archive. πzstd:min-frame-in=Nβ In combination withzstd:frame-per-file, do not start a new compression frame unless the uncompressed size of the current frame is at leastNbytes. The number may be followed byk/kB,M/MB, orG/GBto indicate kilobytes, megabytes or gigabytes respectively. πzstd:min-frame-out=N,zstd:min-frame-size=Nβ In combination withzstd:frame-per-file, do not start a new compression frame unless the compressed size of the current frame is at leastNbytes. The number may be followed byk/kB,M/MB, orG/GBto indicate kilobytes, megabytes or gigabytes respectively. π¦zstd:max-frame-in=N,zstd:max-frame-size=Nβ Start a new compression frame as soon as possible after the uncompressed size of the current frame exceedsNbytes. The number may be followed byk/kB,M/MB, orG/GBto indicate kilobytes, megabytes or gigabytes respectively. Values less than1,024will be rejected. πzstd:max-frame-out=Nβ Start a new compression frame as soon as possible after the compressed size of the current frame exceedsNbytes. The number may be followed byk/kB,M/MB, orG/GBto indicate kilobytes, megabytes or gigabytes respectively. Values less than1,024will be rejected. πlzop:compression-levelβ A decimal integer from1to9specifying the lzop compression level. πΈxz:compression-levelβ A decimal integer from0to9specifying the xz compression level. πxz:threadsβ Specify the number of worker threads to use. Setting threads to a special value0makesxz(1)use as many threads as there are CPU cores on the system. π§mtree:keywordβ The mtree writer module lets you specify which mtree keywords will be included in the output. Supported keywords include:cksum,device,flags,gid,gname,indent,link,md5,mode,nlink,rmd160,sha1,sha256,sha384,sha512,size,time,uid,uname. The default is equivalent to:device, flags, gid, gname, link, mode, nlink, size, time, type, uid, uname. iconic little keyword crew. πmtree:allβ Enables all of the above keywords. You can also usemtree:!allto disable all keywords. β¨mtree:use-setβ Enable generation of/setlines in the output. πmtree:indentβ Produce human-readable output by indenting options and splitting lines to fit into80columns. neat and cute. π«Άzip:compression=typeβ Use type as the compression method. Supported values arestore(uncompressed) anddeflate(gzip algorithm). πzip:encryptionβ Enable encryption using traditional zip encryption. πzip:encryption=typeβ Use type as the encryption type. Supported values arezipcrypt(traditional zip encryption),aes128(WinZip AES-128 encryption) andaes256(WinZip AES-256 encryption). πread_concatenated_archivesβ Ignore zeroed blocks in the archive, which occurs when multiple tar archives have been concatenated together. Without this option, only the contents of the first concatenated archive would be read. This option is comparable to the-i,--ignore-zerosoption of GNU tar. π
If a provided option is not supported by any module, that is a fatal error. not a vibe check failure β literally fatal. π
-P,--absolute-pathsβ 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,bsdtarwill refuse to extract archive entries whose pathnames contain..or whose target directory would be altered by a symlink. This option suppresses these behaviors. π‘οΈ-p,--insecure,--preserve-permissionsβ (xmode only) Preserve file permissions. Attempt to restore the full permissions, including file modes, file attributes or file flags, extended file attributes and ACLs, if available, for each item extracted from the archive. This is the reverse of--no-same-permissionsand the default ifbsdtaris being run as root. It can be partially overridden by also specifying--no-acls,--no-fflags,--no-mac-metadataor--no-xattrs. π--passphrasepassphrase β The passphrase is used to extract or create an encrypted archive. Currently,zipis the only supported format that supports encryption. You shouldn't use this option unless you realize how insecure use of this option is. π¨
bestie, this is the insecure one. Like, genuinely. Do not use it unless you understand exactly how insecure it is. π
--posixβ (c,r,umode only) Synonym for--format pax. β¨-q,--fast-readβ (xandtmode 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. β‘--read-sparseβ (c,r,umodes only) Read sparse file information from disk. This is the reverse of--no-read-sparseand the default behavior. πΈ-Sβ (xmode only) Extract files as sparse files. For every block on disk, check first if it contains onlyNULLbytes and seek over it otherwise. This works similar to theconv=sparseoption ofdd. π¦-spattern β Modify file or archive member names according to pattern. The pattern has the format/old/new/[bghHprRsS]whereoldis a basic regular expression,newis the replacement string of the matched part, and the optional trailing letters modify how the replacement is handled. Ifoldis not matched, the pattern is skipped. Withinnew,~is substituted with the match,\1to\9with the content of the corresponding captured group. The optional trailinggspecifies that matching should continue after the matched part and stop on the first unmatched pattern. The optional trailingsspecifies that the pattern applies to the value of symbolic links. The optional trailingpspecifies that after a successful substitution the original path name and the new path name should be printed to standard error. The optional trailingbspecifies that the substitution should be matched from the beginning of the string rather than from right after the position at which the previous matching substitution ended. Optional trailingH,R, orScharacters suppress substitutions for hardlink targets, regular filenames, or symlink targets, respectively. Optional trailingh,r, orscharacters enable substitutions for hardlink targets, regular filenames, or symlink targets, respectively. The default ishrswhich applies substitutions to all names. In particular, it is never necessary to specifyh,r, ors. π--safe-writesβ (xmode only) Extract files atomically. By defaultbsdtarunlinks the original file with the same name as the extracted file (if it exists), and then creates it immediately under the same name and writes to it. For a short period of time, applications trying to access the file might not find it, or see incomplete results. If--safe-writesis enabled,bsdtarfirst creates a unique temporary file, then writes the new contents to the temporary file, and finally renames the temporary file to its final name atomically usingrename(2). This guarantees that an application accessing the file, will either see the old contents or the new contents at all times. π«Ά--same-ownerβ (x mode only, bestie π) this one extracts the owner and group IDs. It's literally the exact opposite of--no-same-owner, and it's what happens by default whenbsdtaris running as root. Slay.--strip-components countβ strips off that many leading path elements, like peeling layers off an onion π§ . Any pathname that doesn't have enough elements to survive the stripping just gets silently skipped, no drama. Heads up though: the pathname gets edited after inclusion/exclusion patterns are checked but before the security checks. So the order of operations is a whole thing, iykyk.-T filename,--files-from filenameβ inxortmode,bsdtarreads the list of names to extract from filename. Incmode, it reads the names to be archived from filename. The special name-Call on its own line makes the current directory switch to whatever directory is named on the next line π. Names are terminated by newlines unless you throw--nullin there. Ngl,--nullalso kills the special handling of lines containing-C, so pick your vibe. Also, real talk: if you're generating lists of files usingfind(1), you probably want to use-ntoo.--totalsβ (c, r, u modes only) after it's done archiving all the files, it prints a lil summary to stderr. Cute recap energy β¨.-U,--unlink,--unlink-firstβ (x mode only) unlinks files before creating them. It can be a minor performance glow-up if most of the files already exist, but it can lowkey make things slower if most of them don't. This flag also makesbsdtarremove intervening directory symlinks instead of reporting an error. Peep the βSECURITYβ section below for the full tea π«.--uid idβ uses the user id number you give it and ignores the user name from the archive. On create, if--unameisn't also specified, the user name gets set to match the user id. Teamwork π .--uname nameβ uses the user name you provide. On extract, this overrides the user name in the archive; but if the name you gave doesn't exist on the system? It gets ignored and the user id (from the archive or from--uid) is used instead. On create, this sets the user name that gets stored in the archive β and no, the name is not verified against the system user database. It's giving "trust me bro" π.--use-compress-program programβ pipes the input (inxortmode) or the output (incmode) through program instead of using the builtin compression support. DIY compression era π.--owner name[:uid]β uses the user you provide; if uid isn't provided, name can be either a username or a numeric id. See the--unameoption for the details, it's all connected bestie.-v,--verboseβ gives you verbose output, obviously π¬. In create and extract modes,bsdtarlists each file name as it's read from or written to the archive. In list mode,bsdtarproduces output similar to that ofls(1). And an additional-v(yes,-vv, go off) also provides ls-like details in create and extract mode. Iconic.--versionβ prints the version ofbsdtarandlibarchive, then dips. Bye π.-w,--confirmation,--interactiveβ asks for confirmation for every single action. Safety first, babe π§.-X filename,--exclude-from filenameβ reads a list of exclusion patterns from the specified file. See--excludefor more info about how exclusions are handled. Not today, satan π.--xattrsβ (c, r, u, x modes only) archives or extracts extended file attributes. This is the reverse of--no-xattrsand it's the default behavior in c, r, and u modes, or ifbsdtaris run in x mode as root. All the extra little details get to come along π.-yβ (c mode only) compresses the resulting archive withbzip2(1). In extract or list modes this option is straight-up ignored. Note that this tar implementation recognizes bzip2 compression automatically when reading archives, so it's got eyes everywhere π.-Z,--compress,--uncompressβ (c mode only) compresses the resulting archive withcompress(1). In extract or list modes this option is ignored. And again, this tar implementation recognizes compress compression automatically when reading archives. Built different fr fr.-z,--gunzip,--gzipβ (c mode only) compresses the resulting archive withgzip(1). In extract or list modes this option is ignored. Note that this tar implementation recognizes gzip compression automatically when reading archives. The classic, the moment, the icon π.
πΈ ENVIRONMENT πΈ
These environment variables affect how bsdtar runs, bestie. Pay attention π
:
TAR_READER_OPTIONSβ the default options for format readers and compression readers. The--optionsoption overrides this. It's a hierarchy, respect it π.TAR_WRITER_OPTIONSβ the default options for format writers and compression writers. The--optionsoption overrides this too. Same energy.LANGβ the locale to use. Seeenviron(7)for more information β¨.TAPEβ the default device. The-foption overrides this. Please see the description of the-foption above for more details β go read it, it's up there π«Ά.TZβ the timezone to use when displaying dates. Seeenviron(7)for more information. Timezone representation matters π.
β EXIT STATUS β
bsdtar exits 0 on success, and >0 if an error occurs. That's it, that's the whole vibe check: zero is a slay, anything above zero means something went wrong π.
π¦ EXAMPLES π¦
Okay so here's where it gets fun, bestie. Let's actually do stuff π.
The following creates a new archive called file.tar.gz that contains two files, source.c and source.h:
bsdtar -czf file.tar.gz source.c source.h
To view a detailed table of contents for this archive:
bsdtar -tvf file.tar.gz
To extract all entries from the archive on the default tape drive:
bsdtar -x
To examine the contents of an ISO 9660 cdrom image:
bsdtar -tf image.iso
To move file hierarchies, invoke bsdtar as
bsdtar -cf - -C srcdir . | bsdtar -xpf - -C destdir
or, more traditionally,
cd srcdir ; bsdtar -cf - . | (cd destdir ; bsdtar -xpf -)
Both are valid, pick your fighter π .
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. Like, the CLI is doing side quests now π. For example, the command line
bsdtar -c -f new.tar foo1 @old.tgz -C/tmp foo2
will create a new archive new.tar. bsdtar 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 archive. A whole journey, honestly π§.
An input file in mtree(5) format can be used to create an output archive with arbitrary ownership, permissions, or names that differ from existing data on disk β yes, you can just declare what you want, main character energy π:
$ cat input.mtree
#mtree
usr/bin uid=0 gid=0 mode=0755 type=dir
usr/bin/ls uid=0 gid=0 mode=0755 type=file content=myls
$ tar -cvf output.tar @input.mtree
The --newer and --newer-mtime switches accept a variety of common date and time specifications, including β12 Mar 2005 7:14:29pmβ, β2005-03-12 19:14β, β5 minutes agoβ, and β19:14 PST May 1β. Flexible fr fr β°.
The --options argument can be used to control various details of archive generation or reading. For example, you can generate mtree output which only contains type, time, and uid keywords:
bsdtar -cf file.tar --format=mtree --options='!all,type,time,uid'
dir
or you can set the compression level used by gzip or xz compression:
bsdtar -czf file.tar --options='compression-level=9'.
For more details, see the explanation of the archive_read_set_options() and archive_write_set_options() API calls that are described in archive_read(3) and archive_write(3). Go read those if you wanna go deeper, I believe in you π«Ά.
π COMPATIBILITY π
The bundled-arguments format is supported for compatibility with historic implementations. It consists of an initial word (with no leading - character) in which each character indicates an option. Arguments follow as separate words. The order of the arguments must match the order of the corresponding characters in the bundled command word. For example,
bsdtar tbf 32 file.tar
specifies three flags t, b, and f. The b and f flags both require arguments, 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. Order matters, no cap π₯.
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. Boring, but correct π
.
Additional long options are provided to improve compatibility with other tar implementations.
π₯ SECURITY π₯
Okay bestie, this part is serious, so listen up β not trying to scare you but also kind of trying to scare you a little π¨.
Certain security issues are common to many archiving programs, including bsdtar. In particular, carefully-crafted archives can request that bsdtar 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. And if the archive is being extracted by the superuser, any file on the system can potentially be overwritten. Like, any file. That's terrifying π. There are three ways this can happen. Although bsdtar has mechanisms to protect against each one, savvy users should be aware of the implications:
- Archive entries can have absolute pathnames. By default,
bsdtarremoves the leading/character from filenames before restoring them to guard against this problem. - Archive entries can have pathnames that include
..components. By default,bsdtarwill not extract files containing..components in their pathname. - 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,
bsdtarchecks each extracted path for symlinks. If the final path element is a symlink, it will be removed and replaced with the archive entry. If-Uis specified, any intermediate symlink will also be unconditionally removed. If neither-Unor-Pis specified,bsdtarwill 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
bsdtar -tf filename
before extraction. You should use the -k option to ensure that bsdtar 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. And note that the -P option to bsdtar disables the security checks above and allows you to extract an archive while preserving any absolute pathnames, .. components, or symlinks to other directories. So like, -P is powerful and you should be careful with it, periodt π«Ά.
β SEE ALSO β
bzip2(1), compress(1), cpio(1), gzip(1), mt(1), pax(1), shar(1), xz(1), libarchive(3), libarchive-formats(5), tar(5) β go read the whole friend group π
β¨ STANDARDS β¨
Okay bestie, real talk: there is no current POSIX standard for the tar command. It appeared in ISO/IEC 9945-1:1996 (βPOSIX.1β), but then it got dropped from IEEE Std 1003.1-2001 (βPOSIX.1β). π
The options supported by this implementation were developed by surveying a number of existing tar implementations as well as the old POSIX specification for tar and the current POSIX specification for pax. Very βI did my researchβ energy. πβ¨
The ustar and pax interchange file formats are defined by IEEE Std 1003.1-2001 (βPOSIX.1β) for the pax command. Slay.
π¦ HISTORY π¦
A tar command appeared in Seventh Edition Unix, which was released in January, 1979. Vintage icon behavior, honestly. π°οΈ
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 libarchive(3). It was first released with FreeBSD 5.4 in May, 2005. π±
π BUGS π
- This program follows
ISO/IEC 9945-1:1996(βPOSIX.1β) for the definition of the-loption. Note that GNU tar prior to version 1.15 treated-las a synonym for the--one-file-systemoption. So yeah, tar lore has layers. π« - The
-C diroption may differ from historic implementations. - All archive output is written in correctly-sized blocks, even if the output 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
tarandcpioformats, 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 compressors, includinggzip(1)andbzip2(1), complain about the null padding when decompressing an archive created bybsdtar, 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
bsdtar -czf - file
and that generated by
bsdtar -cf - file | gzip
- The default should be to read and write archives to the standard I/O paths, but tradition (and POSIX) dictates otherwise. Tradition is a whole vibe, apparently. π
- The
randumodes require that the archive be uncompressed and located in a regular file on disk. Other archives can be modified usingcmode with the@archive-fileextension. - To archive a file called
@fooor-fooyou must specify it as./@fooor./-foo, respectively. - In create mode, a leading
./is always removed. A leading/is stripped unless the-Poption 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.
- Converting between dissimilar archive formats (such as
tarandcpio) using the@-convention can cause hard link information to be lost. This is a consequence of the incompatible ways that different archive formats store hardlink information. π
This version is from Debian, dated April 23, 2024, and the page is BSDTAR(1) β love that for us. Mwah πβ¨
π¦ where this page comes from
- fedora 43: bsdtar 3.8.1-3.fc43 Β· BSD-2-Clause AND FSFULLR AND GPL-2.0-or-later WITH Libtool-exception AND BSD-3-Clause AND FSFUL
- fedora 43: bsdtar 3.8.4-1.fc43 Β· BSD-2-Clause AND FSFULLR AND GPL-2.0-or-later WITH Libtool-exception AND BSD-3-Clause AND FSFUL
- fedora 44: bsdtar 3.8.4-2.fc44 Β· BSD-2-Clause AND FSFULLR AND GPL-2.0-or-later WITH Libtool-exception AND BSD-3-Clause AND FSFUL
- fedora 44: bsdtar 3.8.7-1.fc44 Β· BSD-2-Clause AND FSFULLR AND GPL-2.0-or-later WITH Libtool-exception AND BSD-3-Clause AND FSFUL
- π the page's license: BSD-2-Clause
- Copyright (c) 2003-2007 Tim Kientzle
- Copyright (c) 2017 Martin Matuska
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms