0

I working on a JFS filsystem made with the option -O (case insensitive filenames).

How can I easily rename a file from Test.txt to test.txt ?

Using mv report the error:

mv: ‘Test.txt’ and ‘test.txt’ are the same file

And nautilus reports

The name “test.txt” is already used in this location. Please use a different name.

Now I can rename it to Test2.txt followed by renaming to test.txt

hultqvist
  • 724

1 Answers1

0

You can use the rename command.

It's not actually a built-in shell command, like mv, but a pearl script that comes by default with most GNU/Linux distros. It's usage is a bit different from mv because it uses Pearl regular expressions to compare against a list of files.

Here's how to use it in your case:

rename 's/Test\.txt/test\.txt/' *

The s tells the rename command to search and replace all occurrences of Test.txt with test.txt. The dots . inside the regular expression must be escaped with a \, that's why the filenames are written like Test\.txt. Notice the * at the end of the command, that means to look through all files in the current directory.

You can pass the -n option to the rename command if you want to test it without making any changes.

devius
  • 1,229