How to change suffix of the files

filesrename

In a directory structure which has multiple subfolders and files in it, some of the file names have the suffix _create (e.g. java1_create) and some of them with _bak (java2_bak).

I need to rename only the files with suffix _create as _bak, so that all the files should have the _bak suffix.

Is there any command or script to do this?

Best Answer

On Linux, assuming that none of your file names have _create inside them (only at the end), you can use the rename utility from the util-linux package, which is installed on all non-embedded Linux systems. Call find to execute the command on all files in subdirectories recursively.

find -depth -exec rename _create _bak {} +

On Debian and derived distributions (Ubuntu, Mint, …) that ship a Perl script as rename, either call rename.ul instead of rename, or replace rename _create _bak by rename 's/_create$/_bak/'.

Related Question