tar
Updated: September 28, 2024
Tar saves many files together into a single disk archive, and can restore files from the archive.
Table of Contents
tldr
# create archive and write it to a file
tar cf target.tar file1 file2 file3
# create zipped archive and write it to a file
tar czf target.tar.gz file1 file2 file3
# extract a compressed archive
tar xvf source.tar.[gx|bz2|xz]
# extract a compressed archive to target directory
tar xvf source.tar.[gx|bz2|xz] --directory=directory
# list the contents of a tar file
tar tvf source.tar
ARGUMENTS
tar
-a, --auto-compress # archive
-c, --create # create an archive containing items
-f, --file # read | write from specified file
-j, --bzip, --bzip2 # compress with bzip
-k, --keep-old-files # do not overwrite existing files
--keep-newer-files # do not overwrite existing files that are newer
-o, --format # use group and user running program instead of the archive
-p, --preserve-permissions # preserve file permissions (acls && xattrs)
-r, --append # like c but adding to archive
-t, --list # list archived items to STDOUT
-u, --update # like r but requites newer modification date
-w, --interactive # confirm every action
-x, --extract # extract to disk from archive
-y, --bzip2 # compress with bzip2
-z, --gzip # compress with gzip
-C, --directory <dir> # target directory
-J, --xz # must use with c
-O, --to-stdout # extract to STDOUT instead of disk
-P, --absolute-paths # preserve pathnames
-U, --unlink # unlink files before creating them
-Z, --compress # compress with compress
--uname <name> # use provided user name
Make from a tar.gz
tar.gz are files that need to be compiled. Sometimes they use autoconf so the process requires that you check the readme.md.
tar -xzfv file.tar.gz
cd <archive-name>
./configure
make
sudo make install