1 min read

Batch Rename Files in Ubuntu & Windows

When using Ubuntu, I can easily rename batch files according to a specific pattern within the default File Manager. However, in Windows, this feature isn’t readily available.

Fortunately, we can achieve similar results using PowerShell. For example, if I want to rename a set of images to sequential numbers like 1.jpg, 2.jpg, and so on, I can use the following script:

cd C:\path\of\your\folder
 
$i = 1
 
Get-ChildItem *.jpg | ForEach-Object {
    Rename-Item $_ -NewName "$i.jpg"
    $i++
}

Ubuntu bash version:

cd /path/of/your/folder
 
a=1
for i in *.jpg; do
  mv "$i" "$a.jpg"
  let a=a+1
done

This method provides a quick and efficient way to rename files in both operating systems.