This question already has an answer here:

I have 40 mp4 files in a folder.

Every file starts with video_. Every file is of format video_*.mp4.

I need to rename all the files with video_ removed from the begining of every file. How can I do that from terminal?

marked as duplicate by kos, Avinash Raj, Pilot6, Jacob Vlijm, Community Sep 22 '15 at 12:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    @JacobVlijm I know we have lots of these questions. But for a newbie it is not clear how to use the other answer. And this is not quite a duplicate. – Pilot6 Sep 22 '15 at 15:56

You can do it by a terminal command in a directory where these files are located.

rename 's/^video_//' *.mp4

That means select all filenames started with video_ and replace video_ with nothing. I guess s is for "substitute".

^ shows the beginning of string. If you omit ^, the first occurrence of video_ will be removed no matter where it is located in the string. But in your case it does not really matter.

Note: Ubuntu versions above 17.04 don't ship with rename package, however you can still install it from default repositories via sudo apt install rename

  • or rename 's/^.*?_//' *.mp4 – Avinash Raj Sep 22 '15 at 12:00
  • Every file starts with video_. Every file is of format video_*.mp4. – Avinash Raj Sep 22 '15 at 12:05
  • what does s/ and // mean in rename 's/^video_//' *.mp4 ? – kashish Sep 22 '15 at 12:15
  • @AvinashRaj Ah you're right, my bad. Then, if we're golfing, rename 's/.*?_//' *.mp4 ;) – kos Sep 22 '15 at 12:17
  • @kashish You can read the duplicate link. There is a good explanation. – Pilot6 Sep 22 '15 at 12:19
  • Using rename (prename) :

    rename -n 's/^video_//' video_*.mp4

    If you are satisfies with the changes that are going to be made, remove -n to let the operation happens actually :

    rename 's/^video_//' video_*.mp4
  • Using bash parameter expansion :

    for file in video_*.mp4; do mv -i "$file" "${file#video_}"; done
    • ${file#video_} is the parameter expansion pattern to remove video_ from the start of the file names.


    for file in video_*.mp4; do mv -i "$file" "${file/video_/}"; done        
    • This one assumes video_ comes only once in file names

    • ${file/video_/} is a bash parameter expansion pattern that will replace video_ from file names with blank.


Using rename

rename 's/^video_//' *.mp4

Not the answer you're looking for? Browse other questions tagged or ask your own question.