Using the perl rename
utility.
Note: perl rename is also known as file-rename
, perl-rename
, or prename
. Not to be confused with the rename
utility from util-linux
which has completely different and incompatible capabilities and command-line options.
rename -n 's/\s*\[\s*(NarutoG|720p|x265|pseudo)\s*\]\s*//ig' *.mkv
This will remove all instances of "NarutoG", "720p", "x265", and "pseudo" inside square brackets from the filenames, including any leading or trailing whitespace (both inside and outside the square brackets). You can add other words/strings inside the parentheses, just make sure they're separated by |
(which is the regexp "alternation" character - this|that
means "this
OR that
").
Square brackets have a special meaning inside a regular expression, so they need to be escaped with \
, as \[
and \]
.
\s*
means zero-or-more whitespace (tabs, spaces, newlines, etc) characters.
If you want it to remove all "word" characters (alphanumeric plus underscore plus some other punctuation and unicode characters - see man perlre
and read about \w
for details) inside square brackets, try this instead:
rename -n 's/\s*\[\s*\w+\s*\]\s*//ig' *.mkv
\w+
means one-or-more "word" characters.
Note that the -n
option in both examples above makes them a dry run, so they will only show what they would do without actually renaming any files. Remove the -n
, or replace it with -v
for verbose output, when you've confirmed they do what you want.