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

1 Answer 1

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.

4
  • sorry did not work, same type of error message: .... already exists.
    – hultqvist
    Commented Oct 20, 2013 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
    Commented Oct 20, 2013 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
    Commented Oct 20, 2013 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
    Commented Oct 20, 2013 at 15:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .