SoFunction
Updated on 2025-04-13

Several ways to batch rename files in Shell

In Linux system, use the following command to implement the requirements:

1. Append the extension (retain the original extension):

find dt\=202* -type f -name 'par*' -exec mv -v -- {} {}.csv \;

Example effects:

2. Replace the extension (delete the original extension):

find dt\=202* -type f -name 'par*' -exec sh -c 'mv -v -- "$1" "${1%.*}.csv"' _ {} \;

Example effects:​​​​​​​

Notes:

  • dt\=202*In\Used for escape=Symbols to prevent shell parsing errors;

  • The command-type fMake sure to process only files;

  • -name 'par*'Match the file name starting with par;

  • use-execPerform operations on each matching file;

  • It is recommended to pass firstechoTest command effect:

find dt\=202* -type f -name 'par*' -exec echo mv -- {} {}.csv \;

Remove after confirmationechoPerform actual modifications.

Summarize

This is the end of this article about several methods for Shell to implement batch renaming files. For more relevant Shell batch renaming files, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!