Как массово переименовывать файлы из командной строки?

Когда я копирую файлы с камеры на компьютер, расширение имени файла указывается в верхнем регистре. Я нашел этот вопрос и ответ, но предложенное решение не работает .

Мой вопрос: почему предлагаемое решение не работает и как мне выполнить переименование файлов, чтобы я только изменял имя файла, делая расширение строчным?

ПРИМЕЧАНИЕ. Файлы хранятся на сетевом хранилище (Synology DS1813+).

Вот моя попытка переименовать файлы:

$ ls
IMG_8809.JPG  IMG_8813.JPG  IMG_8817.JPG  IMG_8821.JPG  IMG_8825.JPG  IMG_8829.JPG  IMG_8833.JPG  IMG_8837.JPG  IMG_8841.JPG  IMG_8845.JPG  IMG_8849.JPG  Thumbs.db
IMG_8810.JPG  IMG_8814.JPG  IMG_8818.JPG  IMG_8822.JPG  IMG_8826.JPG  IMG_8830.JPG  IMG_8834.JPG  IMG_8838.JPG  IMG_8842.JPG  IMG_8846.JPG  IMG_8850.JPG
IMG_8811.JPG  IMG_8815.JPG  IMG_8819.JPG  IMG_8823.JPG  IMG_8827.JPG  IMG_8831.JPG  IMG_8835.JPG  IMG_8839.JPG  IMG_8843.JPG  IMG_8847.JPG  IMG_8851.JPG
IMG_8812.JPG  IMG_8816.JPG  IMG_8820.JPG  IMG_8824.JPG  IMG_8828.JPG  IMG_8832.JPG  IMG_8836.JPG  IMG_8840.JPG  IMG_8844.JPG  IMG_8848.JPG  IMG_8852.JPG
$ find . -name '*.*' -exec sh -c 'a=$(echo {} | sed -r "s/([^.]*)\$/\L\1/"); [ "$a" != "{}" ] && mv "{}" "$a" ' \;
mv: ‘./IMG_8835.JPG’ and ‘./IMG_8835.jpg’ are the same file
mv: ‘./IMG_8822.JPG’ and ‘./IMG_8822.jpg’ are the same file
mv: ‘./IMG_8830.JPG’ and ‘./IMG_8830.jpg’ are the same file
mv: ‘./IMG_8850.JPG’ and ‘./IMG_8850.jpg’ are the same file
mv: ‘./IMG_8820.JPG’ and ‘./IMG_8820.jpg’ are the same file
mv: ‘./IMG_8826.JPG’ and ‘./IMG_8826.jpg’ are the same file
mv: ‘./IMG_8847.JPG’ and ‘./IMG_8847.jpg’ are the same file
mv: ‘./IMG_8816.JPG’ and ‘./IMG_8816.jpg’ are the same file
mv: ‘./IMG_8819.JPG’ and ‘./IMG_8819.jpg’ are the same file
mv: ‘./IMG_8814.JPG’ and ‘./IMG_8814.jpg’ are the same file
mv: ‘./IMG_8810.JPG’ and ‘./IMG_8810.jpg’ are the same file
mv: ‘./IMG_8817.JPG’ and ‘./IMG_8817.jpg’ are the same file
mv: ‘./IMG_8809.JPG’ and ‘./IMG_8809.jpg’ are the same file
mv: ‘./IMG_8851.JPG’ and ‘./IMG_8851.jpg’ are the same file
mv: ‘./IMG_8844.JPG’ and ‘./IMG_8844.jpg’ are the same file
mv: ‘./IMG_8818.JPG’ and ‘./IMG_8818.jpg’ are the same file
mv: ‘./IMG_8823.JPG’ and ‘./IMG_8823.jpg’ are the same file
mv: ‘./IMG_8848.JPG’ and ‘./IMG_8848.jpg’ are the same file
mv: ‘./IMG_8842.JPG’ and ‘./IMG_8842.jpg’ are the same file
mv: ‘./IMG_8815.JPG’ and ‘./IMG_8815.jpg’ are the same file
mv: ‘./IMG_8837.JPG’ and ‘./IMG_8837.jpg’ are the same file
mv: ‘./IMG_8827.JPG’ and ‘./IMG_8827.jpg’ are the same file
mv: ‘./IMG_8825.JPG’ and ‘./IMG_8825.jpg’ are the same file
mv: ‘./IMG_8840.JPG’ and ‘./IMG_8840.jpg’ are the same file
mv: ‘./IMG_8812.JPG’ and ‘./IMG_8812.jpg’ are the same file
mv: ‘./IMG_8811.JPG’ and ‘./IMG_8811.jpg’ are the same file
mv: ‘./IMG_8836.JPG’ and ‘./IMG_8836.jpg’ are the same file
mv: ‘./IMG_8828.JPG’ and ‘./IMG_8828.jpg’ are the same file
mv: ‘./IMG_8832.JPG’ and ‘./IMG_8832.jpg’ are the same file
mv: ‘./IMG_8839.JPG’ and ‘./IMG_8839.jpg’ are the same file
mv: ‘./IMG_8831.JPG’ and ‘./IMG_8831.jpg’ are the same file
mv: ‘./IMG_8824.JPG’ and ‘./IMG_8824.jpg’ are the same file
mv: ‘./IMG_8813.JPG’ and ‘./IMG_8813.jpg’ are the same file
mv: ‘./IMG_8843.JPG’ and ‘./IMG_8843.jpg’ are the same file
mv: ‘./IMG_8846.JPG’ and ‘./IMG_8846.jpg’ are the same file
mv: ‘./IMG_8829.JPG’ and ‘./IMG_8829.jpg’ are the same file
mv: ‘./IMG_8821.JPG’ and ‘./IMG_8821.jpg’ are the same file
mv: ‘./IMG_8838.JPG’ and ‘./IMG_8838.jpg’ are the same file
mv: ‘./IMG_8833.JPG’ and ‘./IMG_8833.jpg’ are the same file
mv: ‘./IMG_8834.JPG’ and ‘./IMG_8834.jpg’ are the same file
mv: ‘./IMG_8845.JPG’ and ‘./IMG_8845.jpg’ are the same file
mv: ‘./IMG_8841.JPG’ and ‘./IMG_8841.jpg’ are the same file
mv: ‘./IMG_8852.JPG’ and ‘./IMG_8852.jpg’ are the same file
mv: ‘./IMG_8849.JPG’ and ‘./IMG_8849.jpg’ are the same file
$ ls
IMG_8809.JPG  IMG_8813.JPG  IMG_8817.JPG  IMG_8821.JPG  IMG_8825.JPG  IMG_8829.JPG  IMG_8833.JPG  IMG_8837.JPG  IMG_8841.JPG  IMG_8845.JPG  IMG_8849.JPG  Thumbs.db
IMG_8810.JPG  IMG_8814.JPG  IMG_8818.JPG  IMG_8822.JPG  IMG_8826.JPG  IMG_8830.JPG  IMG_8834.JPG  IMG_8838.JPG  IMG_8842.JPG  IMG_8846.JPG  IMG_8850.JPG
IMG_8811.JPG  IMG_8815.JPG  IMG_8819.JPG  IMG_8823.JPG  IMG_8827.JPG  IMG_8831.JPG  IMG_8835.JPG  IMG_8839.JPG  IMG_8843.JPG  IMG_8847.JPG  IMG_8851.JPG
IMG_8812.JPG  IMG_8816.JPG  IMG_8820.JPG  IMG_8824.JPG  IMG_8828.JPG  IMG_8832.JPG  IMG_8836.JPG  IMG_8840.JPG  IMG_8844.JPG  IMG_8848.JPG  IMG_8852.JPG

Я также пробовал эту команду с теми же результатами:

$ rename s/.JPG/.jpg/ *.JPG
IMG_8809.JPG not renamed: IMG_8809.jpg already exists
IMG_8810.JPG not renamed: IMG_8810.jpg already exists
IMG_8811.JPG not renamed: IMG_8811.jpg already exists
IMG_8812.JPG not renamed: IMG_8812.jpg already exists
IMG_8813.JPG not renamed: IMG_8813.jpg already exists
IMG_8814.JPG not renamed: IMG_8814.jpg already exists
IMG_8815.JPG not renamed: IMG_8815.jpg already exists
IMG_8816.JPG not renamed: IMG_8816.jpg already exists
IMG_8817.JPG not renamed: IMG_8817.jpg already exists
IMG_8818.JPG not renamed: IMG_8818.jpg already exists
IMG_8819.JPG not renamed: IMG_8819.jpg already exists
IMG_8820.JPG not renamed: IMG_8820.jpg already exists
IMG_8821.JPG not renamed: IMG_8821.jpg already exists
IMG_8822.JPG not renamed: IMG_8822.jpg already exists
IMG_8823.JPG not renamed: IMG_8823.jpg already exists
IMG_8824.JPG not renamed: IMG_8824.jpg already exists
IMG_8825.JPG not renamed: IMG_8825.jpg already exists
IMG_8826.JPG not renamed: IMG_8826.jpg already exists
IMG_8827.JPG not renamed: IMG_8827.jpg already exists
IMG_8828.JPG not renamed: IMG_8828.jpg already exists
IMG_8829.JPG not renamed: IMG_8829.jpg already exists
IMG_8830.JPG not renamed: IMG_8830.jpg already exists
IMG_8831.JPG not renamed: IMG_8831.jpg already exists
IMG_8832.JPG not renamed: IMG_8832.jpg already exists
IMG_8833.JPG not renamed: IMG_8833.jpg already exists
IMG_8834.JPG not renamed: IMG_8834.jpg already exists
IMG_8835.JPG not renamed: IMG_8835.jpg already exists
IMG_8836.JPG not renamed: IMG_8836.jpg already exists
IMG_8837.JPG not renamed: IMG_8837.jpg already exists
IMG_8838.JPG not renamed: IMG_8838.jpg already exists
IMG_8839.JPG not renamed: IMG_8839.jpg already exists
IMG_8840.JPG not renamed: IMG_8840.jpg already exists
IMG_8841.JPG not renamed: IMG_8841.jpg already exists
IMG_8842.JPG not renamed: IMG_8842.jpg already exists
IMG_8843.JPG not renamed: IMG_8843.jpg already exists
IMG_8844.JPG not renamed: IMG_8844.jpg already exists
IMG_8845.JPG not renamed: IMG_8845.jpg already exists
IMG_8846.JPG not renamed: IMG_8846.jpg already exists
IMG_8847.JPG not renamed: IMG_8847.jpg already exists
IMG_8848.JPG not renamed: IMG_8848.jpg already exists
IMG_8849.JPG not renamed: IMG_8849.jpg already exists
IMG_8850.JPG not renamed: IMG_8850.jpg already exists
IMG_8851.JPG not renamed: IMG_8851.jpg already exists
IMG_8852.JPG not renamed: IMG_8852.jpg already exists

ИЗМЕНИТЬ

См. этот вопрос о файловых системах и проблемах с учетом регистра.


person axiopisty    schedule 07.02.2014    source источник
comment
Вы работаете с файловой системой, нечувствительной к регистру? Ваши сообщения об ошибках предполагают, что вы.   -  person William Pursell    schedule 07.02.2014
comment
Неверный синтаксис переименования, нужно избегать точек rename s/\.JPG/\.jpg/ *.JPG   -  person Reinstate Monica Please    schedule 07.02.2014
comment
The files are stored on a NAS (Synology DS1813+). -- Ваша файловая система не поддерживает имена файлов без учета регистра.   -  person devnull    schedule 07.02.2014
comment
Как узнать, не чувствителен ли nas fs к регистру? Я так не думаю. Он работает под управлением Linux. Но очень вероятно, что образы были помещены на NAS, когда он был смонтирован в Windows.   -  person axiopisty    schedule 07.02.2014
comment
Я запускал эти команды из bash в Linux Mint. Я знаю, что fs на этой машине чувствительна к регистру. Nas также нечувствителен к регистру fs. Но изначально файлы помещались на NAS, а доступ к ним осуществлялся через сетевую папку в Windows, которая нечувствительна к регистру.   -  person axiopisty    schedule 07.02.2014
comment
Почему бы просто не переименовать дважды? Сначала переименуйте в фиктивное имя файла, например *.jpg_, а затем переименуйте в *.jpg   -  person Joerg Reinhardt    schedule 07.02.2014
comment
@Joerg - Это, безусловно, достигло бы конечной цели примера, указанного в ОП, с помощью команды переименования. Но меня больше интересует, как решить эту проблему, чтобы я мог использовать первую команду для рекурсивного переименования всех файлов независимо от расширения файла.   -  person axiopisty    schedule 07.02.2014
comment
Я разместил новый вопрос о суперпользователе, который конкретно касается файловых систем и проблем с чувствительностью к регистру. @Joerg, если вы опубликуете свой комментарий в качестве ответа, я приму его, поскольку это обходной путь для конкретного примера в этом вопросе.   -  person axiopisty    schedule 07.02.2014


Ответы (1)


Друг указал мне на это . Связанная статья состоит из 8 страниц, но она многословна в своем объяснении. Краткая версия ответа:

... And that brings me to what I really want to discuss, which is how 
CIFS Server (Samba) deals with this.

As you would expect from an application that was grown to bridge 
the gap between the Unix and Windows worlds, it is very flexible. 
This is both good and bad - with flexibility comes responsibility, 
and sometimes not a little confusion. There are four configuration 
options that Samba provides to allow one to define its behavior 
when dealing with matters of 'case': 

preserve case = (yes/no) 
short preserve case = (yes/no) 
default case = (upper/lower) 
case sensitive = (yes/no)

Решение состоит в том, чтобы настроить Samba на обрабатывать чувствительность к регистру (или проблемы с сохранением регистра) так, как это работает для ваших конкретных потребностей.

person axiopisty    schedule 10.02.2014