Per-user Wget defaults are useful when the same transfer policy has to be applied consistently across interactive commands, cron jobs, and ad-hoc recovery work. Moving those defaults into one startup file reduces repeated typing and lowers the chance of forgetting an important flag during routine downloads.
Wget reads startup commands from configuration files before processing the current command line. The user startup file /$HOME/.wgetrc is the practical place for account-specific defaults, and command-line options still override those settings for one-off runs when a job needs different behavior.
Because every future wget command for that account inherits the file, the startup policy should stay conservative and readable. Keep credentials protected, prefer defaults that are safe for unattended jobs, and use temporary command-line overrides instead of leaving risky experiments behind in /$HOME/.wgetrc.
Steps to configure default options in ~/.wgetrc:
- Back up any existing user startup file before replacing shared defaults for future runs.
$ [ -f ~/.wgetrc ] && cp -a ~/.wgetrc ~/.wgetrc.bak-$(date +%Y%m%d%H%M%S)
A backup is the fastest rollback when scheduled jobs change behavior after a startup-file edit.
- Write a small set of verified defaults to /$HOME/.wgetrc.
$ cat > ~/.wgetrc <<'EOF' # Default Wget behavior for this account. user_agent = WgetBatchDefaults/1.0 tries = 5 timeout = 30 wait = 1 random_wait = on continue = on EOF
Startup-file directives use wgetrc syntax such as user_agent = ... instead of the long CLI option form.
- Restrict the file permissions so saved policy, credentials, or internal endpoints do not leak to other accounts.
$ chmod 600 ~/.wgetrc $ ls -l ~/.wgetrc -rw------- 1 user user 112 Mar 27 06:54 /home/user/.wgetrc
World-readable startup files can expose proxy settings, usernames, or other execution details that should stay private.
- Verify that the startup file changes live request behavior without adding extra flags to the command.
$ wget --spider --debug https://httpbin.org/user-agent 2>&1 | sed -n '/request begin/,/request end/p' ---request begin--- HEAD /user-agent HTTP/1.1 Host: httpbin.org User-Agent: WgetBatchDefaults/1.0 Accept: */* Accept-Encoding: identity Connection: Keep-Alive ---request end---
A visible custom User-Agent in the request block confirms that /$HOME/.wgetrc is being read for that account.
- Override a default on one command line when a single transfer needs different behavior.
$ wget --user-agent='Wget/1.25.0' --spider --debug https://httpbin.org/user-agent 2>&1 | sed -n '/request begin/,/request end/p' ---request begin--- HEAD /user-agent HTTP/1.1 Host: httpbin.org User-Agent: Wget/1.25.0 Accept: */* Accept-Encoding: identity Connection: Keep-Alive ---request end---
Command-line options take precedence, which makes one-off overrides safer than editing the startup file for a temporary test.
- Bypass the startup file entirely during troubleshooting when a clean factory-style run is needed.
$ wget --no-config --spider --debug https://httpbin.org/user-agent 2>&1 | sed -n '/request begin/,/request end/p' ---request begin--- HEAD /user-agent HTTP/1.1 Host: httpbin.org User-Agent: Wget/1.25.0 Accept: */* Accept-Encoding: identity Connection: Keep-Alive ---request end---
Use --no-config to separate binary behavior from local startup-file customizations during incident review.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
