How to Use aria2c to Download and Rename Files on Ubuntu
This article provides a concise guide on managing downloads within the Ubuntu Linux environment using the aria2c utility. It outlines the installation steps and demonstrates how to save files with specific names instead of their original defaults. Readers will learn to apply custom naming conventions and shell patterns to organize data efficiently during the download process.
Install aria2 on Ubuntu
Before using the tool, ensure it is installed on your system. Open your terminal and run the following command to install aria2 from the default repositories:
sudo apt update
sudo apt install aria2Rename a File During Download
To download a file and assign it a specific name immediately, use the
--out flag followed by your desired filename. This
overrides the original filename found in the URL.
aria2c --out="custom-name.zip" https://example.com/file.zipRename Using a Pattern
aria2c does not support internal regex patterns for renaming, but you
can use shell variables to create dynamic patterns. By combining shell
expansion with the --out flag, you can append dates or
timestamps to your filenames automatically.
For example, to add the current date to the filename:
aria2c --out="backup-$(date +%F).zip" https://example.com/file.zipThis command will save the file as
backup-YYYY-MM-DD.zip. You can modify the shell pattern
inside $() to suit your specific naming requirements, such
as adding timestamps or sequential numbers managed by a script.
Verify the Download
Once the command completes, list the files in your directory to confirm the new name was applied correctly:
ls -lhUsing the --out option combined with shell scripting
provides a flexible way to maintain organized downloads without
requiring post-download renaming tools.