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
  • 714
  • 6
  • 16

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,190
  • 1
  • 8
  • 17
  • sorry did not work, same type of error message: .... already exists. – hultqvist Oct 20 '13 at 14:07
  • What about this: `rename 'y/A-Z/a-z/' *`? Note that it will try to rename all files in the current directory to lower case. If none of these options work I'll remove my answer. – devius Oct 20 '13 at 15:28
  • Same error, I assume after the magic is done the end result is still something equivalent to 'mv'. You can remove the answer later if there is a solution, I fear that if you remove it too soon someone else might write a new similar one. – hultqvist Oct 20 '13 at 15:37
  • I presume the correct answer is what you already figured out then: rename to something else and then back to the wanted name. – devius Oct 20 '13 at 15:40