120

Looking to unpack a bunch of files.7z via terminal.

Is there a command-line tool built in, available or I shall install an application that comes with a graphical interface?

bmike
  • 235,889
SuperAtic
  • 1,421
  • 1
    I found a solution here: https://superuser.com/questions/548349/how-can-i-install-7zip-so-i-can-run-it-from-terminal-on-os-x although I haven't tested it yet – ersbygre1 Nov 30 '17 at 03:46

10 Answers10

192

You can install p7zip with Homebrew. So

% brew install p7zip
% 7za x myfiles.7z

Installing Homebrew as @EraserPencil suggested makes sense as the OP might need more programs in the future, which would be at his fingertips then. You can install Homebrew with

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

It should be noted there is 7z e as well but as commented by @Qback, this does almost never do what you want if you have subdirectories in the archive.

  • I have 7zip installed as well. Unfortunately, it said that the archive is damaged and failed to extract the file. Tried installing 7za and it worked like a charm. – Xonshiz May 15 '19 at 12:20
17

The command line version of Unarchive can extract .7z files.

user3439894
  • 58,676
11

MacOS does not handle the .7z format natively.

The UnArchiver is my favourite tool for handling .7z and many other formats. It is available as both an application and a command line tool if that is how you prefer to operate.

Tony Williams
  • 12,142
  • Apples "Archive Utility" handles 7z these days - the question whether built-in command-line-tools can also handle it remains... – user1259710 Aug 14 '23 at 15:33
7

If you don't want to install homebrew, you can install keka (which is an excellent gui for (un)compressing btw) and then link to the included version of p7zip found at Keka.app/Contents/Resources/keka7z

In order to make it function from the command line, I symlinked it into my /usr/local/bin

> ln -s /Applications/Keka.app/Contents/Resources/keka7z /usr/local/bin/7z
> 7z -h

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=utf8,Utf16=on,HugeFiles=on,64 bits,4 CPUs x64)
Modified by aONe for Keka

Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]
       [<@listfiles...>]
Shannon
  • 281
2

We also found another totally free GUI solution that can run on macOS from this other similar question

Keka - the FREE macOS file un/archiver.

SuperAtic
  • 1,421
1

You can install P7ZIP (version 16.02, tested on macOS 10.11 or 10.15) from Rudix. You don't have to install the Rudix ecosystem.

li ki
  • 105
lhf
  • 7,278
0

Turns out that, as of the time of writing, the official 7z distribution has a mac cli client download - currently 7-Zip 21.07 (2021-12-26).

Download, unzip then run - works beatifully:

$ /Users/me/Downloads/7z2107-mac/7zz x some.7z

The first time you run it will fail with the "Unknown developer" prompt - you must give it permissions in the System preferences dialog

nohillside
  • 100,768
Mr_and_Mrs_D
  • 101
  • 2
0

The official 7z distribution release is available in brew.

$ brew install sevenzip

https://formulae.brew.sh/formula/sevenzip

Usage (cli):

$ 7zz -?

7-Zip (z) 23.01 (x64) : Copyright (c) 1999-2023 Igor Pavlov : 2023-06-20 64-bit locale=en_US.utf-8 Threads:12 OPEN_MAX:65535

Usage: 7zz <command> [<switches>...] <archive_name> [<file_names>...] [@listfile]

<Commands> a : Add files to archive b : Benchmark d : Delete files from archive e : Extract files from archive (without using directory names) h : Calculate hash values for files i : Show information about supported formats l : List contents of archive rn : Rename files in archive t : Test integrity of archive u : Update files to archive x : eXtract files with full paths

Bill Gale
  • 121
-1

While you got an error like this

MacBook-Air ~ % brew install p7zip
Error: Cannot install under Rosetta 2 in ARM default prefix (/opt/homebrew)!
To rerun under ARM use:
    arch -arm64 brew install ...
To install under x86_64, install Homebrew into /usr/local.

Use bellow code for M1 Chip Mac

arch -arm64 brew install p7zip
Vivek
  • 113
  • What do you need arch -arm64 for here? – nohillside Mar 03 '22 at 08:06
  • highly required arch -arm64 in M1 Chip MacBook, if you try to install without arch -arm64 then got an error. – Vivek Mar 04 '22 at 09:29
  • Then your setup is strange. Works without that for me (and others). May be worth asking a new question for this so people can help you to avoid this. – nohillside Mar 04 '22 at 09:30
  • Setup is not strange, M1 Chip architecture is arch -arm64 that's why we need to install any brew command with the same architecture, other intel base mac no need to add arch -arm64. – Vivek Mar 04 '22 at 09:43
  • arch is only required if you want to pick a specific architecture from an universal binary. By default an M1 machine will automatically pick arm64 without any help from the user (unless you set your Terminal to run with Rosetta, but this isn‘t the standard case). – nohillside Mar 04 '22 at 09:54
  • Anyway, what kind of error do you get when you run brew without arch? – nohillside Mar 04 '22 at 09:54
  • You only get this error if you run a shell in x86/rosetta (see the beginning of https://github.com/Homebrew/brew/issues/10313 for more details). Just make sure the shell runs natively. – nohillside Mar 04 '22 at 12:55
-4

Because you are familiar with CLI and coming from a Linux background, you could try Installing GNU-tar on Mac

You'd first need to install Homebrew,

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

then run brew install gnu-tar. Think of brew as the yum, or apt-get equivalent.

Then you can use gtar on your Mac.

# on Mac
$ gtar czvf example.tar.gz example
example/
example/bla.txt

# send it to CentOS
# login to CentOS

$ tar xzvf example.tar.gz
example/
example/bla.txt