18

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?

Pilot6
  • 90,100
  • 91
  • 213
  • 324
kashish
  • 1,332
  • 2
    @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

3 Answers3

33

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

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
Pilot6
  • 90,100
  • 91
  • 213
  • 324
8
  • 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.

    Or

    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.

heemayl
  • 91,753
3

Using rename

rename 's/^video_//' *.mp4
Avinash Raj
  • 78,556
A.B.
  • 90,397