tar

BSD Tar Cheatsheet #

BSD tar is the version available on BSD-based systems and has some differences from GNU tar.

Basic Commands #

Command/OptionExampleDescription
tar -cftar -cf archive.tar file1 file2Create a new archive file (-c for create, -f for file)
tar -xftar -xf archive.tarExtract an archive file (-x for extract, -f for file)
tar -tftar -tf archive.tarList the contents of an archive file (-t for list, -f for file)
tar -czftar -czf archive.tar.gz file1 file2Create a compressed archive with gzip (-z for gzip compression)
tar -xzftar -xzf archive.tar.gzExtract a gzip compressed archive (-z for gzip compression)
tar -jcftar -jcf archive.tar.bz2 file1 file2Create a compressed archive with bzip2 (-j for bzip2 compression)
tar -xjftar -xjf archive.tar.bz2Extract a bzip2 compressed archive (-j for bzip2 compression)
tar -Jcftar -Jcf archive.tar.xz file1 file2Create a compressed archive with xz (-J for xz compression)
tar -xJftar -xJf archive.tar.xzExtract an xz compressed archive (-J for xz compression)

Advanced Options #

Command/OptionExampleDescription
tar -Atar -A -f archive.tarConcatenate archives (-A option)
tar -rtar -r -f archive.tar file3Append files to an existing archive (-r option)
tar -Ctar -cf archive.tar -C /path/to/dir file1Change directory before adding files (-C option)
tar -vtar -cvf archive.tar file1Verbose output showing files being processed (-v option)
tar -ptar -cpf archive.tar file1Preserve file permissions (-p option)
tar --excludetar --exclude='*.tmp' -cf archive.tar *Exclude files matching a pattern from the archive (--exclude option)
tar --transformtar --transform='s/old/new/' -cf archive.tar file1Rename files in the archive (--transform option)
tar -zcvftar -zcvf archive.tar.gz file1Create a gzip compressed archive with verbose output (-z and -v options)

This cheatsheet covers the essential BSD tar commands and options for managing archives.

Cheatsheet Website

Discover our extensive collection of cheatsheets covering various tools and technologies to streamline your workflow.