How can I install 7zip so I can run it from Terminal on OS X

194

35

I would like to be able to run 7zip from the command line on Mac. Does anyone have instructions on how to set this up?

Paul Sheldrake

Posted 2013-02-08T10:35:49.193

Reputation: 3 664

Answers

339

To install p7zip using Homebrew, first update your brew formulae to be sure you are getting the latest p7zip.

$ brew update

Use Homebrew to install p7zip:

$ brew install p7zip

Add all files in the sputnik directory to the compressed file heed.7z:

$ 7z a heed.7z sputnik

Unzip heed.7z:

$ 7z x heed.7z

Troy Harvey

Posted 2013-02-08T10:35:49.193

Reputation: 3 508

11same for macports: sudo port install p7zip no problem – Alan Blount – 2014-08-23T02:39:47.710

1@AlanBlount thanks for adding instructions for MacPorts. – Troy Harvey – 2014-09-10T20:49:57.210

On a tangent, my brew update required sudo, is that ok or not? How can I change its behavior in this case to run without sudo? – pal4life – 2014-09-25T20:37:24.703

1

@pal4life Check the permissions on your Cellar directory.

– Troy Harvey – 2014-10-19T20:38:07.790

What is sputnik? and what is heed? – Matthew Semik – 2016-05-14T05:43:12.943

1@MaciekSemik Example file names. – Sridhar Katakam – 2017-03-14T10:10:20.867

@MaciekSemik https://www.youtube.com/watch?v=t-OCjvbV2Z4

– Troy Harvey – 2017-08-22T20:24:13.270

2I had to come here to find out that the command isn't p7zip, it is 7z... – MikeP – 2017-12-10T00:52:02.393

i would have a better chance of destroying the entire universe by accident than stumbling upon the correct syntax – Zigster – 2018-03-20T23:16:11.753

@MikeP I didn't even realize until I read your comment...! – Valdimar – 2018-06-22T19:26:16.267

Now I only need to figure out how to extract to a sub-folder... – n1000 – 2019-01-14T11:59:01.280

42

On the download page of 7-zip, there are several options for OS X. Unfortunately, they seem to be with a GUI, or not available at the moment.


You can download p7zip though.

p7zip is the command line version of 7-Zip for Unix/Linux, made by an independent developer

It is distributed as Linux binaries and in source code form on Sourceforge.

Download the source code, and run make in the folder you extract the archive to. It will automatically build 7za for your OS. You might need Xcode and its command line tools for this to work.

$ cd Downloads/p7zip_9.20.1
$ make
[...]
$ cd bin
$ ls
7za
$ ./7za 

7-Zip (A) [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=de_DE.UTF-8,Utf16=on,HugeFiles=on,4 CPUs)

Usage: 7za <command> [<switches>...] <archive_name> [<file_names>...]
       [<@listfiles...>]

<Commands>
  a: Add files to archive
  b: Benchmark
  d: Delete files from archive
  e: Extract files from archive (without using directory names)
  l: List contents of archive
  t: Test integrity of archive
  u: Update files to archive
  x: eXtract files with full paths
<Switches>
  -ai[r[-|0]]{@listfile|!wildcard}: Include archives
  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives
  -bd: Disable percentage indicator
  -i[r[-|0]]{@listfile|!wildcard}: Include filenames
  -m{Parameters}: set compression Method
  -o{Directory}: set Output directory
  -p{Password}: set Password
  -r[-|0]: Recurse subdirectories
  -scs{UTF-8 | WIN | DOS}: set charset for list files
  -sfx[{name}]: Create SFX archive
  -si[{name}]: read data from stdin
  -slt: show technical information for l (List) command
  -so: write data to stdout
  -ssc[-]: set sensitive case mode
  -t{Type}: Set type of archive
  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options
  -v{Size}[b|k|m|g]: Create volumes
  -w[{path}]: assign Work directory. Empty path means a temporary directory
  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames
  -y: assume Yes on all queries

$ ./7za a 7za.7z 7za 

7-Zip (A) [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=de_DE.UTF-8,Utf16=on,HugeFiles=on,4 CPUs)
Scanning

Creating archive 7za.7z

Compressing  7za      

Everything is Ok

$ ls
7za    7za.7z

Daniel Beck

Posted 2013-02-08T10:35:49.193

Reputation: 98 421

1Before "make" I had to issue command "cp makefile.macosx_64bits makefile.machine" – chrisinmtown – 2015-03-16T16:47:06.217

16

If you only need to extract archives, unar (a command line version of The Unarchiver) also supports 7zip.

Lri

Posted 2013-02-08T10:35:49.193

Reputation: 34 501