close
close

topicnews · August 26, 2024

3 Linux commands I use to download files and their differences

3 Linux commands I use to download files and their differences

severija/Getty Images

Have you ever used Secure Shell to access a remote computer, only to find that you needed to download a file from a remote location? What do you do? Since you can only access this remote computer through a terminal window, you can’t open a web browser and download the file as you normally would.

Also: Want a programming job? Make sure you learn these three languages

Fortunately, these Linux commands make downloading files from a local or remote location pretty easy. I’ll show you three of them: wget, lure, And scp.

1. wget

The wget command is my go-to for downloading remote files to a local machine when no GUI is available. There are two reasons why I tend to default to wget: This is the first command I learned for this purpose and it is very simple.

Suppose you need to download the file. You can do this with the following command:

wget http://www.example.com/file.zip

The wget The command offers several handy options. For example, if a download is interrupted, you can resume it where it left off by using the following command:

wget -c http://www.example.com/file.zip

Or maybe you want to download the file under a different name. To do this, simply use the -O option (for output file), like this:

wget -O newnamez.ip http://www.example.com/file.zip

If you want to download the file to a specific directory, the command is:

wget -P /home/$USER/Downloads http://www.example.com/file.zip

You can also create a text file with the full addresses to access multiple downloads. Let’s say you create the file downloads.txt. In this file, you add one URL per line. You can then download all these files with a single command:

2. Curls

Next we have Lockewhich is a slightly different caliber. If you use curl to download a file without options, Locke will essentially print the contents of the file in the terminal window. For this reason, you must Locke to save the file, which is done with the -O option as follows:

curl -O http://www.example.com/file.zip

You can also save the remote file under a different name, like this:

curl -o newname.zip http://www.example.com/file.zip

Another practical Locke Function: You can use so-called globbing, which allows you to specify multiple URLs at once.

Also: Linus Torvalds talks about AI, the introduction of Rust and why the Linux kernel is “the only thing that matters”

Suppose you need to download the files file1.zip, file2.zip, file3.zip, file4.zip and file5.zip with a single command. Just use brackets like this:

curl http://www.example.com/file[1-5].zip

All five files are downloaded to the current working directory.

3. scp

The scp Command is part of Secure Shell and allows you to copy files from a remote computer with a little more security. scp works with Secure Shell, you must be able to log on to the remote computer with a valid user.

Also: 5 Linux terminal apps that are better than your default app (and why)

Let’s say the file.zip is located on a remote machine on your network and you have a valid account on the host machine. For example, let’s say the remote machine’s IP address is 192.168.1.11 and the local username is olivia. To download the file from that machine, the command is:

scp [email protected]:/home/olivia/file.zip file.zip

The above command will prompt you for Olivia’s user password and after successful authentication, the file.zip will be downloaded to the current working directory on the local computer.

Also: How to use the scp command in Linux

Note that without an account on the remote computer you cannot use scp to download a file.

Although all three of these Linux commands can be used to download files, if you want to know, my preference is wget all the way (unless I need to add a security layer, at which point I use scp).