How to batch rename files using a shell?

To rename multiple files using shell, you can use a for loop combined with the mv command. Here is a simple example:

To rename all files ending in .txt to end in .bak in bulk, you can use the following command:

for file in *.txt; do
  mv "$file" "${file%.txt}.bak"
done

In the above command, “for file in *.txt” will loop through all files ending in .txt, and then use the “mv” command to rename the files with an ending of .bak. “${file%.txt}” will remove the .txt part from the file name and then add .bak at the end.

Please be careful when performing batch renaming operations to avoid accidentally deleting or overwriting important files. It is recommended to back up important files before proceeding.

bannerAds