How to Force aria2 to Overwrite Existing Files?
This article provides a quick overview and practical guide on how to
configure the aria2 download utility to automatically overwrite existing
files on your disk without prompting for user input. By default, aria2
tends to resume downloads or create new files with a modified name (like
file.1.ext) when a naming conflict occurs. By leveraging
specific command-line flags or configuration file settings, you can
force the utility to replace old files seamlessly, making it ideal for
automated scripts and cron jobs.
The Problem with Default Behavior
When you download a file using aria2 and a file with the exact same name already exists in the target directory, aria2’s default behavior is to either:
- Attempt to resume the download if the file is incomplete.
- Append a suffix to the new file (e.g.,
download.tar.gzbecomesdownload.tar.gz.1) to prevent data loss.
In automated environments, this can lead to cluttered directories and broken paths for subsequent scripts that expect the original filename.
The Solution: Using the Right Flags
To force aria2 to overwrite an existing file, you need to combine two
specific command-line options: --allow-overwrite=true and
--auto-file-renaming=false.
Here is how the standard command looks:
aria2c --allow-overwrite=true --auto-file-renaming=false "https://example.com/file.zip"Breakdown of the Options
--allow-overwrite=true: This explicit directive tells aria2 that it is permitted to restart a download from scratch and overwrite the existing file on the disk if it cannot be resumed.--auto-file-renaming=false: This turns off the mechanism that adds.1,.2, etc., to the filename when a conflict is detected. Disabling this ensures the file maintains its intended name, forcing the overwrite to take place.
Making it Permanent via Configuration
If you want aria2 to always overwrite files without needing to type
these flags every time, you can add them to your aria2 configuration
file (usually located at ~/.config/aria2/aria2.conf or
~/.aria2/aria2.conf).
Open your configuration file and add the following lines:
allow-overwrite=true
auto-file-renaming=false
Once saved, any standard aria2c [URL] command will
automatically overwrite existing files without prompting you or renaming
the incoming download.