This will do the job:
Firstly: Install rename
by running the following command in the terminal:
sudo apt install rename
Secondly: In the terminal,cd
to the directory containing your files.
Finally: Rename the files to your desired format by running the following command in the terminal:
rename 's/^(.+)\.(.+)\.(.+)\.(.+)\.(.+)\.mp4$/$1$2.mp4/' *
Done
Notice:
To see how the rename
command will operate on your files but without really renaming them ( just print the output to the terminal ), you can add the option -n
after it. Like so:
rename -n 's/^(.+)\.(.+)\.(.+)\.(.+)\.(.+)\.mp4$/$1$2.mp4/' *
Explanation - as requested by Hamza:
Part # 1:
's/ORIGINAL/NEW/'
Substitutes the ORIGINAL
string with the NEW
string.
To see how it works as simple as it gets:
- Please run in the terminal
rename -n 's/file.number1.2010.720p.otherinfo.mp4/NEW.mp4/' *
- Assuming you have a file named
file.number1.2010.720p.otherinfo.mp4
in the current directory.
- The output would be
rename(file.number1.2010.720p.otherinfo.mp4, NEW.mp4)
Part # 2:
^(.+)\.(.+)\.(.+)\.(.+)\.(.+)\.mp4$
Starts at the beginning of the string ^
and then matches one or more character/s ( any character ) (.+)
before the dot \.
This group is put into a variable $1
and repeated four more times ( five in total ) each group is put into a variable ( $2
, $3
, $4
, $5
) until .mp4
represented as \.mp4
is reached.
Makes sure the string ends with .mp4
by using the $
symbol which matches the end of the string.
This part is, however, a bit flexible and will give you undesired results if the file naming is inconsistent and you have files with more than five parts separated by dots in their names like file.number1.2010.720p.otherinfo.extrainfo.mp4
If this is the case, please substitute this part with the more strict regular expression below. This way it will only operate on files with five parts separated by dots in their names only:
^([^.]+)\.([^.]+)\.([^.]+)\.([^.]+)\.([^.]+)\.mp4$
Part # 3:
$1$2.mp4
Defines the new file name as what is under the variable for the first group $1
( in this case file
) + what is under the variable for the second group $2
( in this case number(x)
) + .mp4
Part # 4:
*
Operates on all the files in the current directory.
man rename
andman rename.ul
. – Rinzwind Aug 13 '19 at 18:22