Download & Unzip Files Without Leaving the Linux Terminal With These 6 Commands

Download & Unzip Files Without Leaving the Linux Terminal With These 6 Commands

I used to download and unzip files with a browser and file manager until I realized I could do it all from the terminal, without clicking or switching windows. I now use just six commands all the time. Here’s what they are and why they’re worth memorizing.

Start With Wget: My Default for Quick Downloads

The first command I ever used to download something from the command line was Wget. It’s built into most Linux distributions and super easy to use.

Want to download a file from a URL? Just run:

wget 
Terminal showing wget successfully downloading a zip file from a remote server.

That’s it. The file gets saved in your current working directory. If you want to rename the file as it downloads, you can use the -O option:

wget -O newname.zip 

This is useful when the URL has a long or weird filename, and you want to keep things tidy.

Another option I often use is -q, which tells wget to run quietly. There will be no output unless there’s an error:

wget -q 

This is handy in scripts or when I don’t want the terminal cluttered with progress output.

When wget Fails, I Use cURL

In most cases, Wget gets the job done. But sometimes it doesn’t work, especially if the file is behind a redirect or the server expects different headers. That’s when I switch to cURL.

Here’s the basic syntax I use:

curl -L  -o file.zip
Terminal output showing the use of curl -L to download a 10MB ZIP file and save it as testfile.zip.

The -L flag tells curl to follow redirects. The command might fail without it if the URL points to a redirect instead of the actual file. The -o flag just tells curl what to name the file once it’s downloaded.

I’ll be honest, cURL has a steep learning curve if you start digging into all its options. However, this command covers most use cases for simple file downloads.

Related

cURL vs. wget in Linux: What’s the Difference?

They’re both best.

After downloading, I almost always need to extract the contents. For ZIP files, the unzip command is straightforward.

To unzip a file in the current directory, just type:

unzip file.zip
Linux terminal showing unzip testfile.zip extracting a video file, followed by an ls command listing the extracted MP4 file and original ZIP archive.

This will extract everything into the current folder. If you want to keep things more organized, you can extract to a specific directory:

unzip file.zip -d myfolder

If the folder doesn’t exist, unzip will create it automatically.

Sometimes I run into issues where I already have some of the files, and I don’t want to overwrite them. In that case, I use:

unzip -n file.zip

The -n option means “never overwrite existing files.” On the flip side, if I’m doing something quick and just want to overwrite without being prompted, I’ll use:

unzip -o file.zip

That saves me from answering “yes” or “no” a dozen times.

Related

How to Unzip Files on Android

Have a ZIP file on your Android phone or tablet and don’t know how to open it? We can help.

For tar Archives, I Memorized These tar Variations

ZIP files aren’t the only format you’ll see. On Linux, .tar.gz and .tar.bz2 are just as common, especially when you’re dealing with software packages, source code, or Linux backup archives.

Here’s what I use to extract them:

tar -xzf archive.tar.gz
Terminal showing a folder created after extracting a .tar.gz file.

And for bzip2-compressed files:

tar -xjf archive.tar.bz2

If I want to unpack the contents into a specific directory, I add the -C flag:

tar -xzf archive.tar.gz -C myfolder

What I like about tar is that it lets you preview the contents of the archive before extracting anything:

tar -tf archive.tar.gz

That -t flag stands for “test” or “list,” so you can see what you’re dealing with before unpacking the whole thing.

I like to list the contents before I extract anything, especially if I’m unsure what’s inside. For .zip files, that looks like:

unzip -l file.zip

And for .tar files, I use:

tar -tf file.tar.gz
Terminal output showing the use of tar -tf to preview the contents of the tar.gz file, displaying a list of files inside.

Sometimes an archive contains a single top-level folder, and sometimes a mess of files. Knowing what you’re about to extract helps avoid clutter.

Once I’ve unpacked something, I usually do a quick:

ls

This is just to confirm that everything landed where I expected. Then I cd into the new folder:

cd foldername
Terminal showing folder contents after navigating into an extracted directory.

Bonus: Combine Everything Into One Command

One of the best things about using the terminal is how easily you can chain commands together. For example, here’s how I download and unzip a file in one line:

wget  && unzip files.zip -d extracted/

Or using Curl:

curl -L  -o files.zip && unzip files.zip

I’ve set up a few functions in my .bashrc that let me reuse these commands with any URL. So now I can just run getzip [URL] or gettar [URL] without retyping the whole thing every time.

You’re on Your Way to Terminal Freedom

Learning to download and unzip files without leaving the terminal changed my work. It’s faster, keeps me focused, and works the same across every Linux system I use. Once you’ve done it a few times, it becomes muscle memory.

I highly recommend getting comfortable with these commands if you’re doing any kind of development, scripting, or systems work on Linux. You’ll save time, reduce clicks, and feel more in control of your system.

Leave a Comment

Your email address will not be published. Required fields are marked *