How to Use Command-Line Tools for Bulk File Renaming
Renaming files one by one quickly becomes tedious when a project contains hundreds of photographs, invoices, reports, or audio exports. Selecting each item in a file manager also introduces the risk of missing duplicates or accidentally changing the wrong extension. Automated renaming produces consistent results while leaving you in control of the pattern.
Command-line tools for bulk file renaming apply rules to matching filenames and generate a predictable new name for every match. Utilities such as mv, rename, and PowerShell’s Rename-Item can replace words, change extensions, add dates, or assign sequential numbers. They are especially useful when the same cleanup must be repeated across several folders.
This guide covers Bash on Linux and macOS, plus PowerShell on Windows. The examples work with filenames containing spaces and other special characters. Always begin with a small test folder or a backup, preview the proposed changes, and inspect the mapping before touching original files.
Why bulk renaming deserves a repeatable process
Consistent filenames make digital files easier to locate and share. A Sydney photographer might organise client images as sydney-portrait-001.jpg, while a Melbourne agency could use melbourne-campaign-raw.mov. Standard prefixes keep related material together and prevent generic names such as final-final-2.jpg from circulating indefinitely.
For Australian small businesses, command-line automation is useful because work often crosses platforms. A company may use Windows desktops for administration and macOS laptops for creative production. Files also accumulate in familiar Downloads folders before being moved to shared drives, external disks, or cloud storage. One tested renaming rule can clean up all those destinations without repeating manual work.
Prepare the folder and preview changes
Begin in the correct directory and make a separate copy of anything difficult to reconstruct. Open PowerShell on Windows and use Set-Location, or open a Bash terminal on Linux or macOS and use cd:
Set-Location 'C:\Users\YourName\Downloads\Invoices'
cd ~/Downloads/Invoices
Preview the transformation before applying it. This Bash loop prints the current and proposed names without changing anything:
for file in *.txt; do
[ -e "$file" ] || continue
new="${file//old-text/new-text}"
printf '%s -> %s\n' "$file" "$new"
done
Review the output for unexpected matches, collisions, and empty results. Once satisfied, run the same loop with mv. The -n option prevents an existing destination file from being overwritten:
for file in *.txt; do
[ -e "$file" ] || continue
mv -n -- "$file" "${file//old-text/new-text}"
done
Replace patterns with shell and PowerShell
For regular-expression replacements, systems that provide the Perl rename utility offer a compact approach. The -n flag performs a dry run:
rename -n 's/\.jpeg$/.jpg/' *.jpeg
This utility may already be available on some Linux distributions or can be installed through a package manager such as Homebrew on macOS. Check the installed command’s help before using a different implementation, since similarly named utilities can accept different options.
PowerShell provides an equivalent method for changing extensions:
Get-ChildItem -File -Filter '*.jpeg' | ForEach-Object {
Rename-Item -LiteralPath $_.FullName -NewName ($_.Name -replace '\.jpeg$', '.jpg')
}
Quote paths and treat filenames as literal values rather than executable text. The -- option in Bash stops a filename beginning with a hyphen from being interpreted as a command option. Globs also skip hidden files, so include them only after checking for system files such as .profile or .config.
Renumber files and work recursively
Sequential names are useful when source filenames contain inconsistent camera codes or download suffixes. This Bash example creates three-digit numbers and preserves the alphabetical order in which the glob returns the files:
i=1
for file in *.jpg; do
[ -e "$file" ] || continue
new=$(printf 'sydney-%03d.jpg' "$i")
mv -n -- "$file" "$new"
i=$((i + 1))
done
Alphabetical order is predictable, but it may not reflect capture time or an editing sequence. If order matters, place the intended files into a dedicated folder or generate an explicit list before numbering them.
Nested folders require a recursive operation. In Bash, find can locate matching files while a null-delimited loop safely handles spaces and unusual characters:
find . -type f -name '*.jpg' -print0 |
while IFS= read -r -d '' file; do
mv -n -- "$file" "${file%.jpg}.jpeg"
done
Run this as a Bash script and stay inside the intended directory. A case-only change may also require a temporary intermediate name, particularly on Windows and macOS, where the default file systems treat names that differ only in letter case as identical.
Build filenames for Australian use
Australian users generally recognise day-first dates, so a format such as 04-07-2026 is clearer than an ambiguous month-first version. Use separators and avoid colons because Windows reserves colons in filenames. The date +%d-%m-%Y command produces a day-month-year stamp suitable for many local workflows:
date +%d-%m-%Y
Time zones matter when files originate across Australia. Sydney and Melbourne adjust their clocks for daylight saving, Brisbane remains on the same time throughout the year, and Adelaide uses a half-hour offset from the eastern states. Include a timezone abbreviation or UTC offset when the exact creation time affects sequence.
The Privacy Act 1988 and Australian Privacy Principles can also make filename design relevant to Australian organisations. Names containing client details, residential addresses, case numbers, or medical references may expose personal information even when the file contents remain protected. Use a project code or client reference instead, and retain the detailed mapping in an access-controlled location.
Prevent collisions and keep a rollback path
Renaming tools differ in how they handle existing destinations. Bash mv can overwrite unless you use -n, while PowerShell generally reports an error when a destination already exists. Check for files such as report.pdf and Report.pdf before changing a batch, because case sensitivity varies between Linux, Windows, and macOS.
Keep a mapping outside the folder being processed. Redirecting the preview output to a log lets you reverse individual changes later, but the log must not match the same filename pattern or it may be renamed with the batch. A retained backup remains the safest rollback option, especially when numbers are being reassigned or extensions are changing.
Third-party software can provide previews, undo history, and metadata-based renaming. Before installing an unfamiliar executable, review it using a secure browser sandbox guide, then confirm the publisher, signature, and source. Free utilities are popular with budget-conscious Australian teams, but a reputable download and an available trial are still preferable to a modified or cracked copy.
Turn one rename into a repeatable workflow
Once a command produces the required result, save it as a .sh or .ps1 script. Give the script explicit inputs for the source directory, prefix, extension, and starting number. Keep the preview stage enabled by default, log each old-to-new pair, and stop if the destination folder contains unexpected file types.
Validation should occur before and after execution. Count the matching files, open several renamed items, and confirm that applications still recognise their formats. Changing an extension does not convert the underlying data, so removing .crdownload may be appropriate while replacing .jpg with .png is not.
Teams using both Windows and macOS can maintain separate platform scripts while applying the same naming policy. Store scripts with documented examples and review the logs periodically. This creates an auditable process rather than a collection of commands that only one employee remembers.
Create a disposable copy of a real folder and run the dry-run command on it first. Compare every proposed name, check for collisions, and keep the mapping log outside the renamed directory. Then apply the approved command to live files in small batches, retaining the backup until the workflow has proved reliable.