How to create and extract a 7-zip archive in Linux and Mac

Create an archive of the current directory:

7z a filename.7z

Create an archive of a specific directory:

7z  a  filename.7z  /path-to-dir

Extract a 7z archive in the current directory with full path:

7z  x   filename.7z

Extract a 7z archive in the current directory without directory names:

7z  e filename.7z

You should not have a “-” before a or x. It will not work, a will “Add files to archive” and x will extract an archive with full path.

If you have 7za binary, you can use it as well. In CentOS 7, 7z binary is available only after installing p7zip-plugins.

rpm -qf `which 7za`
p7zip-16.02-2.el7.x86_64
rpm -qf `which 7z`
p7zip-plugins-16.02-2.el7.x86_64

Whereas in Mac, brew install p7zip installs 7z, 7za and 7zr.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s