RAR and ZIP archiving on Linux

The command to install rar in Debian/Ubuntu:

sudo apt-get install rar unrar

Archiving all files and folders in the directories /home/userone/ and /home/usertwo/:

rar a -r -m5 test.rar /home/userone/* /home/usertwo/*

I will describe some keys:
a (adding data)
-m5 (compression from 0 to 5, 0 – no compression)
-r (add recovery information)
-hp (password setting)

Unpacking the archive into the current directory:

rar -e test.rar

Checking the archive:

rar -е test.rar

Archive recovery:

rar -r test.rar

Install zip on Debian/Ubuntu:

sudo apt-get install zip

Archiving all files and folders in the directories /home/userone/ and /home/usertwo/ excluding the directory /home/usertwo/dir/:

zip -r -9 test.zip /home/userone/* /home/usertwo/* -x "/home/usertwo/dir/*"

-r (archive recursively)
-9 (compression ratio from 1 to 9. 0 – no compression)
-x (“/var/log/nginx/*” option excluding archiving of the specified directory or file)
-e (password setting)

Unpacking the zip archive into the current directory:

unzip test.zip

Unpacking the zip archive into the /tmp/ directory:

unzip test.zip -d /tmp/

Unpacking the file.txt file from the archive into the current directory:

unzip test.zip file.txt

View archive contents:

unzip -l test.zip

See also my article:
RAR archives on Linux

Leave a comment

Leave a Reply