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:

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

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.