You may download a ZIP file from the Internet and need to unzip it to a specific directory. On Unix and Linux, you can stay in the command line and unzip a packaged ZIP file to the folder of your choice!
Servers for Hackers Series Overview
- Start with Server Administration as a Developer
- How to Fix Ubuntu/Debian apt-get 404 Not Found Repository Errors
- Fix “sudo command not found”
- Install a Specific Version with apt-get on Ubuntu/Debian
- Fix Ubuntu/Debian apt-get “KEYEXPIRED: The following signatures were invalid”
- How to Test a Cron Job
- How to Unzip Into a Folder
- How to Show Your Elasticsearch Version on Ubuntu/Debian
- Use “which” in Linux to find the Location of an Exetable
- Sort “ls” by Last Changed Date
- How to Shutdown a Machine
- Show Hidden Files and Folders with `ls`
- Case Insensitive Search
- Search Recursive in Subdirectories
- Search all Files in a Directory (Non-Recursively)
- Search in Multiple Log Files
- Search in Selected Files
Unzip Into a Folder
All Linux and Unix systems ship with the unzip command. It’s a command-line utility allowing you to unzip a compressed file.
By default, the unzip command extracts the contents of the ZIP file into the current directory. Instead of polluting the current directory with extracted files, you may unzip the files into a new folder using the unzip -d flag:
# “unzip -d” extracts the content into a directory
unzip path/to/file -d path/to/folder
# Example
unzip fonts.zip -d ./new-future-studio-fonts
Notice: the unzip command won’t create non-existent paths on your disk. If you want to extract the archive into a non-existent folder path, you’ll run into errors.
For example, a directory non-existent-folder does not exist in the current path. If you want to unzip into a subdirectory of this folder, you’ll run into an error.
$ unzip fonts_otf.zip -d ./non-existent-folder/fonts
Archive: fonts_otf.zip
checkdir: cannot create extraction directory: ./non-existent-folder/fonts
No such file or directory
That’s it. Unzipping a file from the command line is pretty straightforward using unzip <file> -d <folder>.