I have folder which contains many .mkv
files that I'd like to rename without having to manually do so.
The pattern is this:
...
[XVC]_Control_-_10_-_Doctors_[SCB055Y].mkv
[XVC]_Control_-_11_-_Engineers_[50OPZ00].mkv
...
I'd like the results to be:
...
Control-10-Doctors.mkv
Control-11-Engineers.mkv
...
I've tried using find
and piping it through sed
and tr
, but I can't seem to get it to work.
This is what I've tried so far:
find . -iname "*.mkv" -exec sed -e 's/\[[^][]*\]//g' {} \;
find . -type f "*mkv" | sed 's/\[[^][]*\]//g' | tr -d '_'
find . "*.mkv" -type f -print0 | xargs -0 sed -i '' -e 's/\[[^][]*\]//g' | tr -d '_'
find . -iname "*.mkv" -exec rename 's/\[[^][]*\]//g' .mkv '{}' \;
find . -iname "*.mkv" -exec rename -n 's/\[[^][]*\]//g' {} ";"
And several others, but none seem to work. I find it puzzling that the command command below works:
(input)
echo '[XVC]_Control_-_10_-_Doctors_[SCB055Y].mkv' | sed 's/\[[^][]*\]//g' | tr -d '_'`
(output)
Control-10-Doctors.mkv
EDIT:
$ file $(which rename)
/usr/bin/rename: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=d7b5a08ee8556c59dbdda26e998e20d4762c2bbc, for GNU/Linux 3.2.0, stripped
rename -n 's/\[.+?\]//g; s/_//g' *mkv
rename: not enough arguments
Try 'rename --help' for more information.
perl
and therename
command installed, if that's what you're thinking of. – telometto Aug 12 '22 at 18:39rename
command you used is the one fromutil-linux
or if it is the perl script often installed asrename
on Debian-based systems. What doesfile $(which rename)
return? Do you have eitherprename
orperl-rename
installed? See What's with all the renames: prename, rename, file-rename? – terdon Aug 12 '22 at 18:47file $(which rename)
will only show a link, and you have to follow that link to find what kind of program it points to (sometimes in several steps). For this reason I made the shellscriptwhat-about
, that does that job for us. See this link. – sudodus Aug 12 '22 at 19:26dpkg
installed; is there an alternative I can use to substitute the command inside the script? – telometto Aug 12 '22 at 19:44what-about: line 73: file: command not found
;dpkg-query: no path found matching pattern /usr/bin/rename
;dpkg-query: no path found matching pattern *rename*
. – telometto Aug 12 '22 at 19:51dnf
) – sudodus Aug 12 '22 at 19:53man rename
in order to check which options and commands that are relevant. They might be [slightly?] different from what should be used in perl rename. – sudodus Aug 12 '22 at 20:11man rename
you might find information telling which version of rename it is. Or runrename -V
– sudodus Aug 12 '22 at 20:22