How do you extract an archive using the shell?

Quick! How do you extract an archive using the shell?

Most of the time, you just want to extract everything to a new directory and then explore.

Unless you’re crusty, remembering how involves a man page, a sigh, and a Google search.

Screw that. If you’re on Debian, just install unp.

unp is a Perl script that makes extraction just work. None of that alphabet soup nonsense from tar!

Install it like this:

iain@turing:~$ sudo apt-get install unp
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
bzip2 unrar unrar-free xdms p7zip p7zip-full cabextract orange
The following NEW packages will be installed:
unp
0 upgraded, 1 newly installed, 0 to remove and 20 not upgraded.
Need to get 0 B/13.6 kB of archives.
After this operation, 102 kB of additional disk space will be used.
Selecting previously deselected package unp.
(Reading database ... 22070 files and directories currently installed.)
Unpacking unp (from .../archives/unp_2.0~pre4_all.deb) ...
Processing triggers for man-db ...
Setting up unp (2.0~pre4) ...

Use it like this to extract the neo4j archive you downloaded earlier:

root@turing:/home/iain# unp neo4j-community-1.9.1-unix.tar.gz
neo4j-community-1.9.1/
[...]
neo4j-community-1.9.1/doc/manual/UPGRADE.txt

I’ve truncated the output here to just the first and last line because this particular archive contains several hundred files.

But it’s as simple as that!

How do you download Neo4j using the shell?

The Neo4j Server Installation documentation has minimal advice:

Download the latest release from http://neo4j.org/download
select the appropriate version for your platform

The website offers this download link for the current stable version of Neo4j on Linux: http://download.neo4j.org/artifact?edition=community&version=1.9.1&distribution=tarball

This works fine in a web browser but not in my shell.

I used wget to fetch the package using that link:

root@turing:/home/iain# wget http://download.neo4j.org/artifact?edition=community&version=1.9.1&distribution=tarball
[1] 14951
[2] 14952
root@turing:/home/iain# --2013-07-04 17:07:12-- http://download.neo4j.org/artifact?edition=community
Resolving download.neo4j.org... 198.101.198.70
Connecting to download.neo4j.org|198.101.198.70|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2013-07-04 17:07:13 ERROR 404: Not Found.
^C
[1]- Exit 8 wget http://download.neo4j.org/artifact?edition=community
[2]+ Done version=1.9.1

After reporting a 404 error, wget hangs until I kill it with CTRL + C.

A website called Geil Things has a Neo4j wiki article that contains the real download link.

The link is hidden in a shell script. The important line looks like this:

wget http://dist.neo4j.org/neo4j-community-${NEWVERSION}-unix.tar.gz

If you replace ${NEWVERSION} with 1.9.1 you get the link the current stable version of Neo4j.

The complete wget command looks like this:

wget http://dist.neo4j.org/neo4j-community-1.9.1-unix.tar.gz

If you run the command in the shell you should see output like this:

root@turing:/home/iain# wget http://dist.neo4j.org/neo4j-community-1.9.1-unix.tar.gz
--2013-07-04 17:21:52-- http://dist.neo4j.org/neo4j-community-1.9.1-unix.tar.gz
Resolving dist.neo4j.org... 178.236.4.60
Connecting to dist.neo4j.org|178.236.4.60|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 37512748 (36M) [application/x-tar]
Saving to: “neo4j-community-1.9.1-unix.tar.gz”
100%[======================================>] 37,512,748 30.5M/s in 1.2s
2013-07-04 17:21:53 (30.5 MB/s) - “neo4j-community-1.9.1-unix.tar.gz” saved [37512748/37512748]

Now you’ve downloaded the archive. You can continue to follow the installation instructions in the documentation.