The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,679 other followers

7za in the OS X Terminal on your Mac

Posted by jpluimers on 2014/01/25

On both Windows and OS X, I use 7zip a lot. Usually the GUI versions (currently 7z920 on Windows and Keka 1.0.4 on OS X).

But for some purposes (for instance: compressing .lnk files) the 7za command-line version is a must (it has lots of options).

Note that the Windows 7za command-line version is 32-bit.

If you handle really large files on Windows, you might want to use the 64-bit 7z.exe that is in `%ProgramFiles%\7-Zip\7z.exe`.

There are a few ways to install the 7za console version on a Mac so you can access 7za from the Terminal in OS X.

You can go the ruby based HomeBrew way or making it install from source (it is open source on GitHub and has many formulas), both of which mean you need to have Xcode and the command-line tools for it installed. If you want that, HomeBrew installs start with the below command and you need to be prepared for some manual labour:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Another alternative would be to install the p7zip from MacPorts.

But since I already have Keka on OS X, and Keka is open source based in p7zip Posix port of 7za, it is even easier than that: just make sure the Keka console binary (keka7z) is aliased in your bash profile.

Note: I tried linking the binary and 7z.so support library using ln, but then got errors like `Can’t load ‘./7z.dll’ ()` () are linked from a directory in the path.

For that just edit your ~/.bash_profile file and add lines like these:

alias 7za='/Applications/Keka.app/Contents/Resources/keka7z'
alias 7z='/Applications/Keka.app/Contents/Resources/keka7z'

Here you go (:

Note that there is a slight artefact that makes keka7z (aliased or not) give you lines containing “No such file or directory” like below when testing archives, but they are harmless.

100.000000: No such file or directory

The end-result counts, which is like this:

Everything is Ok
Folders: 7
Files: 966
Size: 73320970201
Compressed: 37095475219

Here you go (:

Note the keka7z is a fat binary, so the kernel can run it either as a 32-bit x86 (i386) or 64-bit x64 (x86_64) process. You can find out how fat a binary is by using the find command:

bash-3.2$ file /Applications/Keka.app/Contents/Resources/keka7z
/Applications/Keka.app/Contents/Resources/keka7z: Mach-O universal binary with 2 architectures
/Applications/Keka.app/Contents/Resources/keka7z (for architecture i386): Mach-O executable i386
/Applications/Keka.app/Contents/Resources/keka7z (for architecture x86_64): Mach-O 64-bit executable x86_64

–jeroen

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: