Shell – How to rename multiple files in a directory at the same time

filesrenameshell

I have directory say /var/tmp/abc which has 4 files:

12345-ram-3e3r5-io9490-89adu9.csv
45434-dam-qwe35-to9490-43adu9.csv
11234-cam-yy3r5-ro9490-85adu9.csv
14423-sam-hh3r5-uo9490-869du9.csv

I want to rename all the CSV files (find all the files & rename them) in shortest possible (probably one-liner) way to this:

XXXXX-ram-3e3r5-io9490-89adu9.csv
XXXXX-dam-qwe35-to9490-43adu9.csv
XXXXX-cam-yy3r5-ro9490-85adu9.csv
XXXXX-sam-hh3r5-uo9490-869du9.csv

Best Answer

rename -n 's/(\w+)/XXXXX/' *.csv

remove the -n when happy.

Related Question