How to Download a File Using Linux Terminal
Downloading files from the internet using a Linux terminal can be a quick and efficient process. Whether you’re a beginner or an experienced user, this guide will walk you through the steps to download files using the terminal on your Linux system.
Choosing the Right Tool
Before you start downloading files, you need to choose the right tool. The most commonly used tools for downloading files in Linux are `wget` and `curl`. Both are powerful and versatile, but they have their own unique features and syntax.
Tool | Description | Usage |
---|---|---|
wget | Command-line utility for retrieving files using HTTP, HTTPS, and FTP | sudo apt-get install wget |
curl | Command-line tool and library for transferring data using various protocols | sudo apt-get install curl |
Using wget to Download a File
Once you have installed `wget`, you can use it to download files from the internet. Here’s how to do it:
- Open your terminal.
- Use the `wget` command followed by the URL of the file you want to download. For example:
wget http://example.com/file.zip
This command will download the file from the specified URL and save it in the current directory with the same name as the file on the server.
- Optionally, you can specify a different filename for the downloaded file using the `-O` option. For example:
wget -O mydownloadedfile.zip http://example.com/file.zip
This command will save the downloaded file as `mydownloadedfile.zip` in the current directory.
Using curl to Download a File
Similarly, you can use `curl` to download files from the internet. Here’s how to do it:
- Open your terminal.
- Use the `curl` command followed by the URL of the file you want to download. For example:
curl -O http://example.com/file.zip
This command will download the file from the specified URL and save it in the current directory with the same name as the file on the server.
- Optionally, you can specify a different filename for the downloaded file using the `-o` option. For example:
curl -o mydownloadedfile.zip http://example.com/file.zip
This command will save the downloaded file as `mydownloadedfile.zip` in the current directory.
Advanced Downloading Options
Both `wget` and `curl` offer a variety of advanced options for downloading files. Here are some of the most commonly used options:
- -c: Continue the download if it was interrupted.
- -t: Set the number of retries for the download.
- -b: Enable background downloading.
- -L: Follow any redirects.
- -A: Specify the acceptable content types.
- -R: Specify the acceptable range of bytes to download.
For example, to download a file and retry up to 5 times if the download is interrupted, you can use the following command with `wget`:
wget -c -t 5 http://example.com/file.zip
And with `curl`:
curl -c -t 5 -o mydownloadedfile.zip http://example.com/file.zip
Conclusion
Downloading files using the Linux terminal is a straightforward process with the right tools and commands. By using `wget` or `curl`, you can efficiently download files from the internet and save them to your system. Experiment with the various options available to tailor the download process to your needs.