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)?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
This could be one way:
for file in *.mp4?token*; do mv --no-clobber "$file" "${file%%?*}"; done
Method 2
If you have the rename(1) tool (which you do if you have Debian or a Debian-based Linux, including Ubuntu and derivatives):
rename -n 's/.mp4.*$/.mp4/' *mp4*
Once you’re convinced you have the right pattern, just remove the -n (dry-run) and let it run properly.
rename(1) will apply a Perl regular expression to the filenames given it.
Note that on most other Linux distributions, rename is a different file renaming program, which doesn’t help for this particular renaming pattern.
Method 3
There is also mmv:
mmv -n "*.mp4*" "#1.mp4"
Remove the “-n” when output looks right.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0