CentOS: How to Install and Use Wget

/
/
/
211 Views

Wget is used to download files via the CLI. In this friendly tutorial at the beginning, we will show you how to install and use the wget command in CentOS.

Requirements

For this instruction, you only need to access a CentOS system. It could be a server (which is likely) or a desktop with CLI (terminal) access.

If you need an unmanaged server, you can get one from Vultr or Linode. If you need a managed server, get one from SolaDrive.

The wget tutorial will make it work on CentOS 8, CentOS 7, Fedora, etc.

If you look for its instruction, then it means that the wget is missing from your CentOS system and you may get “there is no such error in the file or directory”.

How to fix “-bash: / usr / bin / wget: No such file or directory” in CentOS

So, to fix the error you got, you need to install wget on CentOS.

To install it, run the following command:

yum install wget -y

When done, you can start using wget again.

How to use wget in CentOS – with examples

The basic command syntax is as follows:

wget <options> <url>

You can get a list of available command options and help via this command:

wget -h

For example, if you want to download our logo, you would run:

wget https://thishosting.rocks/wp-content/uploads/2019/01/thishosting-rocks-logo.png

If the URL contains special characters such as *, ?, [ and ], you can quote the URL:

wget "https://example.com/to/a/file?[name].zip"

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 specific 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 is an example:

wget -O example.zip https://file-examples-com.github.io/uploads/2017/02/zip_2MB.zip

Download a file to a targeted directory with -P

By default, wget downloads the file to the working directory (the directory you currently have). If you want to store the file in a different directory, you can use the -P option.

Syntax:

wget -P /new/path/to/file url.to/file.zip

For example:

wget -P /var/www/html https://file-examples-com.github.io/uploads/2017/02/zip_2MB.zip

This command will save the zip_2MB.zip file in / var / www / html.

Download a background file with -b

If it’s a much larger file, you can run the wget command with the -b option to download the file in the background while you do the rest.

Syntax:

wget -b url.to/large.file

For example:

wget -b https://file-examples-com.github.io/uploads/2018/04/file_example_WMV_1920_9_3MB.wmv

Download an entire website with -m

If you need to download an entire website, you can use the -m option to do so. Using the “-m” option is the same as using all options together “-r -N -l inf –no-delete-list”.

Syntax:

wget -m example.com

For example, if you want to download our website:

wget -m https://thishosting.rocks

That’s a lot. That’s the most common use of wget. You can get more information by running wget using the -h option explained earlier or reading the person page with:

man wget

Leave a Comment

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

This div height required for enabling the sticky sidebar