Videos recorded using the OnlineTvRecorder sometimes have a prefix consisting of a five-digit number, for instance:
71072_Vertrauter_Feind_13.06.19_20-15_kabel1_140_TVOON_DE.mpg.HQ.cut.mp4
Of course, these files fail to sort into the list of unprefixed videos and we cannot search a movie by its initial letters.In this situation, the Bash helps us very nicely with its build-in string manipulation functions. The following snippet takes the filename and removes any sequence of digits followed by an underscore (as regex: [0-9]*_) from the beginning of the filename:
filename=71072_Vertrauter_Feind_13.06.19_20-15_kabel1_140_TVOON_DE.mpg.HQ.cut.mp4 new_filename=${filename#[0-9]*_} mv $filename $new_filename
We can pack this into a loop to rename a batch of downloaded files:
for f in *.cut.mp4 do new_filename=${f#[0-9]*_} [ "$f" != "$new_filename" ] && mv $f $new_filename done
The guard expression avoids warnings by mv if the old and new filename equal.
References
- [1] Bash string operations