This article describes how to download a file and save it to disk on your Ubuntu machine using a command line terminal.
The wget command saves to file on disk by default, whereas curl displays the file on screen by default. However, both programs can both display on screen and save to disk.
If you're using an Ubuntu laptop or desktop, you can press Ctrl + Alt + T on your keyboard to open a new terminal window. If you're using a remote Ubuntu server, you can connect using SSH to open a new terminal session.
wget and/or curlUbuntu usually comes with both wget and curl pre-installed, so you can try Step 3 first and come back to this step only if you see an error message like Command 'curl' not found.
If your Ubuntu machine does not already have wget, you can install it using the following command:
$ sudo apt install -y wget
Similarly, if your Ubuntu machine does not already have curl, you can install it using the following command:
$ sudo apt install -y curl
wget or curlwgetTo save the file located at URL https://example.com/index.html, we can run:
$ wget http://example.com/index.html
wget saves the file in the current directory using the same filename specified in the URL (in our example, index.html).
If we want to save it as a different filename, we can use the -O option (an uppercase letter "O" for "Output"). For example, if we want to save the file at URL https://example.com/index.html as example1.html in our current directory, we can run:
$ wget -O example1.html https://example.com/index.html
curlAlternatively, we can use the curl program to download a file to disk. By default, if we run curl https://example.com/index.html, it prints the contents to standard output (stdout). Because standard output in a terminal session is just the terminal window, we'll see the contents show up in the terminal window.
To save the contents to a file on disk using curl, we need to use the -o option (a lowercase letter "o" for "output"). For example, to save the contents of https://example.com/index.html to a file called example2.html in the current directory, we can run:
$ curl -o example2.html https://example.com/index.html