I have some files named like these:



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

3 Answers 3


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.


This could be one way:

for file in *.mp4\?token*; do mv --no-clobber "$file" "${file%%\?*}"; done
  • 1
    you might want to add -n or --no-clobber to mv if there's any chance that one of the mp4's might have the same name. Doesn't seem likely, but it costs nothing.
    – bsd
    Jan 11, 2012 at 15:25

There is also mmv:

mmv -n "*.mp4*" "#1.mp4"

Remove the "-n" when output looks right.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .