Bash – Batch Renaming Files with a Pattern

bashrename

I have some files named like these:

63018933.mp4?token=1325697436_b0c3e70c6e339380b4a484c576a8c287

63808488.mp4?token=1325697401_4ae5f7a68d93873c8881b303e7655e14

How do I rename all them to, for example 63018933.mp4(remove characters after mp4)?

Best Answer

This could be one way:

for file in *.mp4\?token*; do mv --no-clobber "$file" "${file%%\?*}"; done
Related Question