Home > Enterprise >  find and rename files gives bash 'no such file or directory' error
find and rename files gives bash 'no such file or directory' error

Time:08-06

I'm trying to strip the numbers and - from the file name.

Below are the files.

ui-service-3.100.503505.json
kibana-store-end-3.103.103505.json
api-application-3.4003.10350665.json

find . -type f -iname "*.json"  -exec rename 's/[0-9]//g' {} \; 

throws find: ‘rename’: No such file or directory

Tried multiple other combinations but same error.

I'm expecting below output, where am I going wrong ?

ui-service.json
kibana-store-end.json
api-application.json

CodePudding user response:

Probably you don't have rename command on your system. Try this instead:

for file in ./*.json; do
    echo mv "$file" "${file%-*}.json"
done

Drop the echo if the output looks fine.

  • Related