Wget is used to download files via the CLI. In this beginner-friendly tutorial, we’ll show you how to install and use the wget command on CentOS.
For this tutorial, you’ll only need access to a CentOS system. It can be a server (which is most likely) or a desktop with access to the CLI (terminal).
This wget tutorial will work on CentOS 8, CentOS 7, Fedora, etc.
If you’re looking for this tutorial, then it means that wget is missing from your CentOS system and you may get the “no such file or directory error”.
How to fix “-bash: /usr/bin/wget: No such file or directory” on CentOS
So, to fix the error you’re getting, you need to install wget on CentOS.
To install it, run the following command:
yum install wget -y
Once that’s done, you can start using wget again.
How to use wget on CentOS – with examples
The basic command syntax looks like this:
wget <options> <url>
You can get a list of available command options and help via this command:
So, for example, if you wanted to download our logo, you’d run:
If the URL contains special characters like *, ?, [ and ], you can quote the URL:
We’ll go through the most common wget options below.
Download a file under a different filename with -O
If you want to download a certain file but save it with a different filename, use the -O option.
The syntax is:
wget -O newFilename.txt url.to/oldFilename.txt
So, here’s an example:
wget -O example.zip https://file-examples-com.github.io/uploads/2017/02/zip_2MB.zip
Download a file to a specified directory with -P
By default, wget will download the file to the working directory (the directory you’re currently in). If you’d like to save the file to a different directory, you can use the -P option.
wget -P /new/path/to/file url.to/file.zip
wget -P /var/www/html https://file-examples-com.github.io/uploads/2017/02/zip_2MB.zip
This command will save the file zip_2MB.zip to /var/www/html.
Download a file in the background with -b
If it’s a larger file, you can run the wget command with the option -b to download the file in the background while you do something else.
wget -b url.to/large.file
wget -b https://file-examples-com.github.io/uploads/2018/04/file_example_WMV_1920_9_3MB.wmv
Download a full website with -m
If you need to download a full website, you can use the option -m to do so. Using the option “-m” is the same as using all these options together “-r -N -l inf –no-remove-listing”.
wget -m example.com
For example, if you’d like to download our website:
wget -m https://thishosting.rocks
That’s pretty much it. Those are the most common uses of wget. You can get more information by running wget with the -h option as explained earlier or reading the man page with: