Overview
The wgetrc file is a configuration file that Wget references when it runs. There are global configuration files that apply to the entire system and personal configuration files that apply to individual users. This file is useful for modifying Wget's default behavior, reducing repetitive option inputs, and optimizing for specific environments.
Key Features
- Configuration Scope: Global (e.g., `/etc/wgetrc`) and User-specific (e.g., `~/.wgetrc`)
- Precedence: User-specific settings override global settings.
- Key Configuration Items: Download path, proxy, timeout, retries, user agent, etc.
Common wgetrc File Locations
- `/etc/wgetrc` (Global configuration)
- `~/.wgetrc` (User-specific configuration)
Usage Examples
Examples of settings written inside the wgetrc file. This file must be edited directly with a text editor.
Setting the Default Download Directory
# ~/.wgetrc or /etc/wgetrc file content
dir = /home/user/downloads
Configures all downloads to be saved in the `/home/user/downloads` directory.
Proxy Configuration
# ~/.wgetrc or /etc/wgetrc file content
http_proxy = http://proxy.example.com:8080/
https_proxy = http://proxy.example.com:8080/
use_proxy = on
Configures HTTP and HTTPS proxies.
Setting Retry Count and Timeout
# ~/.wgetrc or /etc/wgetrc file content
retries = 10
connect_timeout = 15
Retries up to 10 times on connection failure and sets the connection timeout to 15 seconds.
User Agent Configuration
# ~/.wgetrc or /etc/wgetrc file content
user_agent = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36
Changes the user agent string that Wget uses to identify itself to web servers.
Log File Configuration
# ~/.wgetrc or /etc/wgetrc file content
output_file = /var/log/wget.log
Records all Wget output to a specified log file.
Tips & Precautions
Tips and points to be aware of for effectively using the wgetrc file.
Editing the File
The wgetrc file is a plain text file and can be modified with any text editor such as `vi`, `nano`, or `gedit`.
- If the `~/.wgetrc` file does not exist, you can create it yourself.
- Changes will take effect the next time Wget is executed.
Security Considerations
It is not recommended to store proxy authentication information or sensitive settings directly in the wgetrc file. It may be safer to use environment variables or specify them directly on the Wget command line.
- Set the permissions of the `~/.wgetrc` file to `600` to prevent other users from reading it.
Using a Specific wgetrc File
wget --config=/path/to/my_custom_wgetrc http://example.com/file.zip
To use a specific configuration file instead of the default `wgetrc` file, use the `--config` option.