Question

I've been attempting to use the util-linux version of rename (2011) to replace a specific string in all files with another. While I realize the perl version of rename would offer a solution, I can't figure out how to use this version of rename.

The specific example are a set of files (something--2013.mkv, somethingelse--2011.mkv), and I'm trying to remove the double dashes and replace with a space.

Was it helpful?

Solution

The problem is that rename uses getopt for argument parsing and thus has a special interpretation for double dash (--). -- signifies the end of the arguments.

A solution would be to avoid using -- in your command. One way to do this is to break your command into sub targets, e.g. translate single dash to underscore, then two underscores to single dash:

$ rename - _ *.mkv
$ rename __ - *.mkv

A less roundabout way to do this is to actually use the getopt behavior

$ rename -- -- - *.mkv

OTHER TIPS

The rename from util-linux is in /usr/bin/rename.ul in Ubuntu. So you could use the rename.ul command.

mkdir TEMP
numbers=2011
find . -name "*.mkv" | while read filename
do
  echo mv "$filename" "TEMP/somethingelse_"$((numbers++)).mkv
  rm filename
done
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top