Create a zipped archive of files and directories, and unzip it
$ tar -cvzf archive.tar.gz dir1 dir2 file1 file2
a dir1
a dir2
a file1
a file2
$ ls
archive.tar.gz
Unzip it
tar -xvz archive.tar.gz
-c
: create archive-x
: extract archive-f
: use file name for archive-v
: verbose-z
: compress withgzip
Sometimes I'd like to use bzip
$ tar -cvjf folder.tar.bz folder
folder/
folder/file1.txt
folder/subdir2/
folder/subdir2/file2.txt
folder/subdir1/
folder/subdir1/file1.txt
$ tar -xvjf folder.tar.bz
folder/
folder/file1.txt
folder/subdir2/
folder/subdir2/file2.txt
folder/subdir1/
folder/subdir1/file1.txt
Create a multi-volume zipped archive of files and directories, and restore it
$ tar -cvj folder | split -d -b 99m - "folder.tar.bz"
folder/
folder/file1.txt
folder/subdir2/
folder/subdir2/file2.txt
folder/subdir1/
folder/subdir1/file1.txt
$ ls
folder folder.tar.bz00 folder.tar.bz01
-d
: use numeric suffixes-b
: byte size of volumes
Restore the folder
$ cat folder.tar.bz* > folder.tar.bz
$ ls
folder folder.tar.bz folder.tar.bz00 folder.tar.bz01
$ tar -xvjf folder.tar.bz
folder/
folder/file1.txt
folder/subdir2/
folder/subdir2/file2.txt
folder/subdir1/
folder/subdir1/file1.txt
References
- Gnu Project home page for tar
- FileCompression, Ubuntu Documentation, https://help.ubuntu.com/community/FileCompression