7z CLI Support for OS X

By | 19 Jan 2015

I recently had a need to have shell/command line (CLI) support for the 7z file format on OS X to allow for some scripting. After reviewing various apps that support the 7z format, I found that most do not offer CLI access. After some research and testing I settled on p7zip. p7zip is a port of 7za.exe, the command line version of 7-Zip, for Unix, Linux, and Mac OS X.  Below are the steps I used to install p7zip on OS X (10.9 and 10.10 used with this process).


1. Download and Extract

Download and extract the p7zip source “p7zip_9.20.1_src_all.tar.bz2” to a known location from:
http://sourceforge.net/projects/p7zip/files/p7zip/9.20.1/


2. Edit makefile.machine

Per the README included with the source package (downloaded in step above), “According to your OS, copy makefile.linux, makefile.freebsd, makefile.cygwin, … over makefile.machine”. This puts the correct variables in place to recompile for the specified OS.

Make a backup of makefile.machine prior to overwriting:

cp makefile.machine makefile.machine.backup

Copy the makefile.macosx_64bits file over makefile.machine:

cp makefile.macosx_64bits makefile.machine

3. Make 7za for OS X

Use “make” to build 7za for OS X. If you do not have the command line developer tools or Xcode installed you will be prompted when running make.

CLI Tools Prompt

Example:

$ make
 mkdir -p bin
 /Library/Developer/CommandLineTools/usr/bin/make -C CPP/7zip/Bundles/Alone all
 c++ -m64 -O -DENV_MACOSX -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_REENTRANT -DENV_UNIX -DBREAK_HANDLER -DUNICODE -D_UNICODE -c -I. -I../../../myWindows -I../../../ -I../../../include_windows ../../../myWindows/myGetTickCount.cpp
 ...
 c++ -m64 -O -DENV_MACOSX -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_REENTRANT -DENV_UNIX -I../../C -o my_86_filter my_86_filter.o -framework CoreFoundation
 $

4. Test and use!

7za options and syntax:

$ ./7za
 7-Zip (A) [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
  p7zip Version 9.20 (locale=utf8,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

 

Example – List files in an archive:

$ ./7za l /Users/max/Downloads/MP3352SP.7z 
 
 7-Zip (A) [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
 p7zip Version 9.20 (locale=utf8,Utf16=on,HugeFiles=on,4 CPUs)
 
 Listing archive: /Users/max/Downloads/MP3352SP.7z
 
 --
 Path = /Users/max/Downloads/MP3352SP.7z
 Type = 7z
 Method = LZMA BCJ
 Solid = +
 Blocks = 2
 Physical Size = 25907282
 Headers Size = 713
 
    Date      Time    Attr         Size   Compressed  Name
 ------------------- ----- ------------ ------------  ------------------------
 2010-11-25 19:10:00 ....A       131763     12488520  Richoh MP3352SP/disk1/rica1Ich.chm
 2013-01-22 04:43:07 ....A        15159               Richoh MP3352SP/disk1/Readme.html
 2013-06-02 22:36:56 ....A          534               Richoh MP3352SP/disk1/rica1Icl.ini
 2013-06-04 15:06:48 ....A        21268               Richoh MP3352SP/disk1/rica1i.cat
 2013-06-02 22:37:10 ....A      2956116               Richoh MP3352SP/disk1/rica1Icf.cfz
 2013-06-02 22:37:12 ....A      3091338               Richoh MP3352SP/disk1/rica1Icz.dlz
 2011-02-02 21:11:58 ....A        46219               Richoh MP3352SP/disk1/mfricr64.dl_
 2011-05-30 20:43:56 ....A       510128               Richoh MP3352SP/disk1/mp255d64.dl_
 2011-05-19 13:25:48 ....A       175887               Richoh MP3352SP/disk1/rica1Icb.dl_
 2013-05-13 02:30:30 ....A      1673526               Richoh MP3352SP/disk1/rica1Icd.dl_
 2013-05-13 02:30:30 ....A       676703               Richoh MP3352SP/disk1/rica1Ici.dl_
 2009-09-01 21:30:30 ....A       130901               Richoh MP3352SP/disk1/rica1Icj.dl_
 2007-02-15 17:47:28 ....A        30858               Richoh MP3352SP/disk1/rica1Ict.dl_
 2013-05-13 02:30:30 ....A      1275082               Richoh MP3352SP/disk1/rica1Igr.dl_
 2010-12-06 17:24:06 ....A        17220               Richoh MP3352SP/disk1/rica1Ilm.dl_
 2013-05-13 02:30:30 ....A      2192614               Richoh MP3352SP/disk1/rica1Iug.dl_
 2013-05-13 02:30:30 ....A      1357750               Richoh MP3352SP/disk1/rica1Iui.dl_
 2013-05-13 02:30:30 ....A         1862               Richoh MP3352SP/disk1/rica1Iur.dl_
 2006-08-21 21:59:12 ....A        29362               Richoh MP3352SP/disk1/ricdb64.dl_
 2013-06-02 22:36:56 ....A         1693               Richoh MP3352SP/disk1/OEMSETUP.DSC
 2013-06-02 22:36:56 ....A        10047               Richoh MP3352SP/disk1/OEMSETUP.INF
 2013-06-02 22:36:56 ....A         4161               Richoh MP3352SP/disk1/rica1Iui.irj
 2013-06-02 22:37:10 ....A        22975               Richoh MP3352SP/disk1/rica1Iug.miz
 2013-06-02 22:37:30 ....A        44507               Richoh MP3352SP/disk1/rica1Icd.psz
 2008-06-17 18:47:04 ....A           69               Richoh MP3352SP/disk1/rica1Iui.rcf
 2013-06-02 22:36:56 ....A          300               Richoh MP3352SP/disk1/rica1Iui.rdj
 2014-03-30 16:01:04 ....A     13499352     13418049  Richoh MP3352SP/z61475L11.exe
 2014-03-30 16:02:32 D...A            0            0  Richoh MP3352SP/disk1
 2014-03-30 17:06:55 D....            0            0  Richoh MP3352SP
 ------------------- ----- ------------ ------------  ------------------------
                               27917394     25906569  27 files, 2 foldersx

 

Example – Extract files

$ ./7za x /Users/max/Downloads/MP3352SP.7z
 
 7-Zip (A) [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
 p7zip Version 9.20 (locale=utf8,Utf16=on,HugeFiles=on,4 CPUs)
 
 Processing archive: /Users/max/Downloads/MP3352SP.7z
 
 Extracting  Richoh MP3352SP/disk1/rica1Ich.chm
 Extracting  Richoh MP3352SP/disk1/Readme.html
 Extracting  Richoh MP3352SP/disk1/rica1Icl.ini
 Extracting  Richoh MP3352SP/disk1/rica1i.cat
 Extracting  Richoh MP3352SP/disk1/rica1Icf.cfz
 Extracting  Richoh MP3352SP/disk1/rica1Icz.dlz
 Extracting  Richoh MP3352SP/disk1/mfricr64.dl_
 Extracting  Richoh MP3352SP/disk1/mp255d64.dl_
 Extracting  Richoh MP3352SP/disk1/rica1Icb.dl_
 Extracting  Richoh MP3352SP/disk1/rica1Icd.dl_
 Extracting  Richoh MP3352SP/disk1/rica1Ici.dl_
 Extracting  Richoh MP3352SP/disk1/rica1Icj.dl_
 Extracting  Richoh MP3352SP/disk1/rica1Ict.dl_
 Extracting  Richoh MP3352SP/disk1/rica1Igr.dl_
 Extracting  Richoh MP3352SP/disk1/rica1Ilm.dl_
 Extracting  Richoh MP3352SP/disk1/rica1Iug.dl_
 Extracting  Richoh MP3352SP/disk1/rica1Iui.dl_
 Extracting  Richoh MP3352SP/disk1/rica1Iur.dl_
 Extracting  Richoh MP3352SP/disk1/ricdb64.dl_
 Extracting  Richoh MP3352SP/disk1/OEMSETUP.DSC
 Extracting  Richoh MP3352SP/disk1/OEMSETUP.INF
 Extracting  Richoh MP3352SP/disk1/rica1Iui.irj
 Extracting  Richoh MP3352SP/disk1/rica1Iug.miz
 Extracting  Richoh MP3352SP/disk1/rica1Icd.psz
 Extracting  Richoh MP3352SP/disk1/rica1Iui.rcf
 Extracting  Richoh MP3352SP/disk1/rica1Iui.rdj
 Extracting  Richoh MP3352SP/z61475L11.exe
 Extracting  Richoh MP3352SP/disk1
 Extracting  Richoh MP3352SP
 
 Everything is Ok
 
 Folders: 2
 Files: 27
 Size:       27917394
 Compressed: 25907282

Resources:

Leave a Reply

Your email address will not be published. Required fields are marked *