-c create an archive
-f file.tar filename of archive
-v verbose
--totals statistics for archive creation
Total bytes written: 103157760 (99MiB, 1000MiB/s)
-z archive using gzip, quick but offers less compression
-zf file.tar.gz filename of gzip archive
-j archive using bzip2, slow but offers more compression
-jf file.tar.bz2 filename of bzip2 archive
--remove-files moves files into archive instead of copy
-p preserves file and directory permissions
--owner user override the ownership of files when placed into an archive
--exclude='/directory' --exclude='file' --exclude='*pattern*' exclude directory names, filenames or pattern matches
--ignore-case ignore case when using --exclude=
-h follow and include the content of symlinks
--no-recursion ignore all sub-directories and their content
A file in the current directory.
tar -cf archive.tar filename
A directory.
tar -cf archive.tar /directory/to/backup/*
A set of files and directories.
tar -cf archive.tar file1.txt /path/to/file2.log /different/directory/to/backup/*
tar --totals -czvf ~/archive.tar.gz /var/www/*
Backup and compress the home directory by keeping permissions, but exclude hidden files and directories
tar --totals --exclude='.*' -czvpf ~/archive.tar.gz ~/*
| split pipes the output of tar into split
-d uses numerical instead of alphabetical naming suffixes on the split archives
-b split size
- hyphen placeholder for what would normally be an input filename used by split
tar -cvpz /directory/to/backup/* | split -d -b 1000m - ~/archive.tar.gz
tar -cvpz /directory/to/backup/* | ssh [email protected]:/directory/to/store/backup/ "( cat > archive.tar.gz )"
tar -rvf archive.tar /directory/or/path/to/files/*
Or you can use the update argument that will only append files that are newer than the copies contained within the archive.
tar -uvf archive.tar /directory/or/path/to/files/*
The following will merge the content of archive2.tar into archive1.tar
tar -Avf archive1.tar archive2.tar
While this copy the archive archive2.tar into archive1.tar
tar -rvf archive1.tar archive2.tar
tar -tf archive.tar
-x extract an archive
-f file.tar archive's filename
-v verbose
-C /directory/to/restore/to place restored files into the specified directory
-p preserves file and directory permissions
tar -xf archive.tar
tar -xf archive.tar README
tar -xvzf archive.tar.gz
tar -xvf archive.tar -C ~/downloads
tar -xvjf archive.tar.bz2 -C ~/downloads
Learn more.