Commands.page Logo

How to Specify Custom User Agent String When Using Wget

This article provides a concise guide on changing the user agent string within the wget command on Ubuntu. Modifying this string allows you to mimic specific web browsers or devices, which is useful for accessing websites that block default command-line tools. You will learn the exact syntax and flags required to implement a custom user agent for your download tasks.

To specify a custom user agent in wget, you need to use the --user-agent option or its shorthand -U. By default, wget identifies itself as “Wget/version_number,” which some servers may block. Changing this string makes your request appear as if it is coming from a standard web browser like Chrome or Firefox.

The basic syntax for the command is as follows:

wget --user-agent="YOUR_USER_AGENT_STRING" URL

You can also use the shorter version:

wget -U "YOUR_USER_AGENT_STRING" URL

For example, if you want to mimic a Chrome browser on Linux to download a file from example.com, you would run:

wget --user-agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" http://example.com/file.zip

Ensure you enclose the user agent string in quotes if it contains spaces. This command tells the remote server to treat the request as a standard browser session rather than a script. This method works immediately on any Ubuntu system with wget installed and does not require configuration file changes.