If you’re new to Linux, and have just migrated from Windows, it’ll probably take a bit of time to get used to. But don’t worry. I know the Linux Terminal seems quite intimidating at first, but you must believe this – it is not as hard as you think it is, not at least in every case, and as long as you’re not speaking Server management.
Nevertheless, there are many linux commands that function as plainly as the English Language, and are very easy to interpret. Not all commands are that cheezy, however. In our case though, the unzip command is one of the simplest commands out there, and is tremendously useful if you need to tinker with .zip files. Despite its ease of use, simply trying to run it from the terminal won’t work every time, because it is possible that you don’t even have the command installed in your system!
unzip: command not found
If you don’t have unzip installed, you probably ran into this error when you typed unzip into Bourne Again Shell.
-bourne again shell: unzip: command not found
Or, if you’re using zsh like a lot of Mac users are (since zsh is the default shell in MacOS), you will see this error message instead:
zsh: command not found: unzip
To fix this error, you need to install unzip. Read the next section for how to install unzip.
Install Unzip Command
The unzip command is not shipped by default in most Linux distros out there, but luckily, it can be found in about all of the repositories, because it’s such a common command. The only reason why you may see the “unzip: command not found” error is because it is not installed in your machine, while you’re trying to invoke it looking at suggestions found online to carry out a specific job that requires unzipping .zip files.
To bypass the error, simply install the unzip command by using the package manager of your Linux distributions. But remember, the command to install will not be the same in every distribution, so don’t try a command you see for Ubuntu in a Fedora Linux machine. I’m listing some of the common distributions where you may wish to install the unzip command.
First, open up your terminal and run one of the following commands that go under your specific Linux Distribution.
sudo pacman -Syu unzip
sudo apt-get install unzip
sudo yum install unzip
sudo yum install unzip
sudo yum install unzip
You should now be able to run the unzip command without any issues, or error messages!
There’s one other thing to note, however. If you want to archive a group of files rather than extracting them, the unzip command will not help you achieve that – his brother, zip will. There’s another command called zip, which also does not come shipped by default. To install it, simply replace the “unzip” in the end with “zip” when executing the commands mentioned above. You may wish to check out some tutorials online on how to use it, as it’s a little bit trickier than using unzip to extract the files.
Fix the Path Variable
This shouldn’t be a problem for most people, but it isn’t an impossibility either. That is, the directory where commands like unzip is not scanned by the system. In many cases, such for example when installing whole distribution from scratch, the path variable may not be set to included such directories. In order to fix this, you need to add one line to the .bashrc file located in the home directory of your system if you’re using the Bourne Again Shell. Bashrc is actually a configuration file for bashrc where you can store important settings, and set commands to be executed in the startup of the terminal.
If you’re using a shell other than Bourne Again Shell, then the configuration file may differ, so make sure you know how to do that. For now, add the following line to .bashrc, if you’re using bourne again shell:
This should hopefully fix the problem. If the commands are installed in some other directory instead, then just change the “/usr/bin” part with that specific directory.
How to use Unzip command
There are many flags (options) available for the unzip command to be used along with it, but for the most part, what you’d care about for unzipping a .zip file, is to run the following command:
Replace the filename with the name of the file you’re trying to extract, and make sure to include “.zip” in the end. You should find all the files that have been extracted in the same directory where you used the command. No extra hassle.
Alternatives for Unzip Command
There are quite a few alternatives to the unzip command in Linux, some of which have a GUI (graphical User Interface). However, I’ll only be mentioning the command line ones as they are directly comparable to the unzip command.
The first alternative is the bzip2 command. It also works pretty much the same, but there are two key differences. One being the fact that it can be used for both zipping and unzipping files, so you won’t need to have two separate packages installed. The action you do on a file by using the bzip2 command needs to be specific by using flags like -kv9 and kvd. This will depict whether you zip or unzip a file. However, there’s a downside to this command, which is, you cannot archive multiple files into a single .zip file – they will each be separately archived if you specify multiple files when running the command.
The other common alternative to the unzip command is the gzip command, which can also be used for both zipping and unzipping files in your Linux machine. It is pretty much the same as bzip2, but there are a few cool sides to this one. Firstly, it is more lightweight as compared to the other commands that’re mentioned, even though the magnitude of such small programs won’t leave footprints in your disk space anyway.
But the fun part here is that if you install gzip, you get another command besides casually running gzip in your terminal. It is the gunzip command. What’s cool about it is that if all you wish to do is simply unzip a .zip file, just like the unzip command, you can use gunzip and then specify the name of the file you want to extract, without needing to pass any flags like you needed to in bzip2, and saves you a few keystrokes!
The Linux terminal might seem like a nerd’s toy, but in no way is that a fact. It might not look as fancy as the GUI most people are used to nowadays, but it certainly is something you should not ignore for the sake of being harder to use than clicking buttons with a mouse. Not all commands are that hard, probably. In fact, for most tasks that require a lot of micromanagement, the terminal is way more efficient, time saving and less stressful to use. Just to give you a hint, you can select all the files that have a .zip extension, which are stored together with hundreds of other files, and then move them to another folder by using just a single line of command in the terminal instead of selecting every .zip files one by one using a mouse. Gotcha, mice lovers!