1zip <archive.zip> <file1> <file2> # compress files.
2zip -r <archive.zip> <directory> # compress a directory.
3unzip archive_name.zip [-d directory] # decompress an archive.
gzip is based on the Deflate algorithm (a combination of the LZ77 and Huffman algorithms).
1gzip -l # show the size of the uncompressed file.
2gzip <file> # compress.
3gunzip <file.gz> | gzip -d <file.gz> # decompress.
4gzip -9 <my_file> # compress a file optimally.
5gzip -c <file1> <file2> > compressed_file.gz # compress several files into a single one.
bzip2 is an alternative to gzip, more efficient but slower.
Preserve files permissions and ownership.
The Basics
1# Archive
2tar cvf my_archive.tar <file1> <file2> </dir/folder/>
3
4## Archive and compress with zstd everything in the current dir and push to /target/dir
5tar -I zstd -vcf archive.tar.zstd -C /target/dir .
6
7# Extract
8tar xvf my_archive.tar
9
10# Extract and push to target dir
11tar -zxvf new.tar.gz -C /target/dir
Other useful options โข t : list archive’s content. โข T : archive list given by a file. โข P : preserve absolute path (useful for backing up /etc). โข X : exclude. โข z : gunzip compression. โข j : bzip2 compression. โข J : lzma compression.
1rsync -arv --info=progress2 photo backup_photo
a = archive โ preserves permissions (owner, group), times, symbolic links and devices.r = recursive โ copies directories and sub-directories.v = verbose โ prints what is being copied.1rsync -apvz --stats --update --exclude gsast/olap_cubes --exclude gsast/param user@server-src:/export/ user@server-dest:/home/
2rsync -av -e ssh root@192.168.1.10:/backup/DUMP/* .
3rsync -azp --stats root@oracle-src:/ec/sw/oracle/client/product/12.2.0.1/network/mesg/ ~/mesg/
4rsync -azp /home/user/mesg/ root@oracle-dest.example.com:/ec/sw/oracle/client/product/12.2.0.1/network/mesg/
5
6ssh root@oracle-dest.example.com "ls -lrt /ec/sw/oracle/client/product/12.2.0.1/network/mesg/"
7ssh root@oracle-dest.example.com "chown oracle:dc_dba /ec/sw/oracle/client/product/12.2.0.1/network/mesg/*"
8
9rsync -aS --delete --rsh /export/home backup-host:/export/save
If you delete files in the source directory, rsync does not propagate the deletion to the backup directory unless you add the --delete option.