Linux rename не работает

Rename command not working as expected

but nothing is happening. I have also tried ‘s/\.nc2/:00:00/g’ and ‘s/.nc2/:00:00/g’ , but as expected this also didn’t work. Any idea of what might be wrong? Thank you.

1 Answer 1

Actually found out the reason it wasn’t working is because in the machine I’m working there is a weird version of rename whose syntax is actually rename from to files* . Hadn’t seen that one before.

On Linux there are at least three different programs named rename . The one you mention seems to be the rename(1) from util-linux . You probably want a Perl script version, which is sometimes named prename .

@lcd047 Is there an alternative command that I can use that is sure to be the same in every Linux distro? Cause I assume we have an issue much like find (which is the same in every distro) and locate (which differs).

I have no idea, sorry, but I’m probably not the right person to ask. I’m not using Linux much these days.

You must log in to answer this question.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533

Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group.
This site is not affiliated with Linus Torvalds or The Open Group in any way.

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Why rename simply doesn’t work?

I need to rename multiple files, and some tutorials shows that the command rename is the best option instead of just use mv for each file. But then I have these files:

 ReconhecimentoImagens2021-10-18--2020-2.mp4 ReconhecimentoImagens2021-11-01--2020-2.mp4 ReconhecimentoImagens2021-11-22--2020-2.mp4 ReconhecimentoImagens2021-10-25--2020-2.mp4 ReconhecimentoImagens2021-11-08--2020-2.mp4 ReconhecimentoImagens2021-11-24--2020-2.mp4 'ReconhecimentoImagens2021-11-01--2020-2(2).mp4' ReconhecimentoImagens2021-11-17--2020-2.mp4 ReconhecimentoImagens2021-11-29--2020-2.mp4 

and NOTHING happens, I get code 4 that according to the man page means ‘nothing was renamed’. I searched for multiple tutorials and nobody seems to be doing anything different than that so, what am I doing wrong here?

Читайте также:  Apache hadoop on linux

Are you using the perl version of rename (AKA prename , perl-rename , file-rename )? or some other rename (like the one in the util-linux package)? Find out by running rename -V — if it mentions perl or File::Rename at all (e.g. /usr/bin/rename using File::Rename version 1.30, File::Rename::Options version 1.10 ) then it’s the perl rename. If not, then it isn’t — and has completely different capabilities and options. If you’re using some other rename, I recommend installing and using the perl rename (e.g. on Debian and related distros sudo apt-get install rename ).

util-linux’s rename is a completely different program with completely different and incompatible options and capabilities. Either read man rename to figure out how to use it (it won’t be anything like rename ‘s/2021/ /’ *.mp4 ) or (highly recommended) install the perl rename utility.

1 Answer 1

There’s different versions of rename, and yours isn’t the one with PERL regex support.

For most Linux distros and other unixoid systems, there’s some package that contains the rename.pl or simply rename command that’s built from perl.

In your use case, the «classical» util-linux rename fully suffices:

Honestly, my shell does well enough that I don’t have to remember all these fine things. I learned sed somewhat OK-ish once, I’ve learned my shell’s for syntax once, and that’s it:

for filename in *.mp4 ; do mv "$" "$(echo "$" | sed 's/regex/replacement/')" done 

is pretty easy to remember for me, at least, and should work in bash and zsh and other bourne-alike shells. Not an extra command I have to learn.

In fact, if you want things to be simple, you can use your own favourite shell’s variable expansion to its fullest extent:

#!/usr/bin/env zsh if [[ "$" -lt 2 ]] ; then echo "Usage: $ [-r] PATTERN REPLACEMENT [FILE. ]" echo "Uses normal Zsh globbing for pattern, unless -r is specified:" echo "In that case, use the regexp-replace loadable ZSH function" exit 1 fi if [[ "$" = "-r" ]]; then autoload regexp-replace REGEX=1 shift 1 else set -o extendedglob REGEX=0 fi PATTERN="$" REPLACEMENT="$" shift 2 if [[ "$" -eq 0 ]]; then for filename in $ ; do mv "$" "$" || echo "Problem renaming $" >&2 done else for filename in $ ; do original_filename="$ regexp_replace filename "$" "$" mv "$ "$" || echo "Problem renaming $" >&2 done fi 

Источник

rename not working [closed]

This question was closed because the problem as described can’t be reproduced. It is not currently accepting answers.

This describes a problem that can’t be reproduced, that seemingly went away on its own or was only relevant to a very specific period of time. It’s off-topic as it’s unlikely to help future readers.

rename -v 's/Karton 1/brauner Karton/g' * rename -v 's/Karton 1/brauner Karton/g' *.jpeg 

According to a lot of examples this shouldn’t be that hard. What am I doing wrong? Aditional info: «Karton 1» would be «[B/b]ox 1» in English.

What exactly happened? Was there any output? You may be using the wrong rename . You don’t need to escape spaces in regex, btw. Also, please show your real filenames — do not add quotes, . characters etc that are not really there!

rename.ul is the wrong rename for this syntax. You need Perl rename ( file-rename ). Are you using Ubuntu?

1 Answer 1

There are several versions of the rename command. Use rename —version to determine which you have, they use different syntax.

$ rename --version /usr/bin/rename using File::Rename version 0.20 $ rename 's/\.jpeg$/.jpg/' * $ rename --version rename from util-linux 2.30.2 $ rename .jpeg .jpg * 

He’s got the one I have. Mine is util-linux 2.30.2, I ran into this issue a year ago and couldn’t figure out how to get rename to work again. if I had only looked at the man page.

Linked

Hot Network Questions

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533

Ubuntu and the circle of friends logo are trade marks of Canonical Limited and are used under licence.

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Почему в Ubuntu перестала работать команда rename?

sim3x

Такого файла нет, однако путём экспериментов я нашёл в чём причина. Причина в «девчячих» символах-картинках. Типо сердечков, нот и т.д. Вопрос теперь, как массово их убрать от туда, из под командной строки муторно. Нужно решение под оболочку Убунту или Win. На Win нашёл решение, однако оно убирает ASCII символы, а файлы с нотам и сердечками переименовать не может 🙁

ILoveYAnny

ILoveYAnny

Да, так всё переименовалось, не могли бы вы подсказать логику этого дополнения? И есть ли что-то, что поможет убрать символы лишние..

Mystray

ILoveYAnny: Это общепринятая практика при работе с аргументами: двойной минус означает, что дальше ключей не будет, а все аргументы следует считать входными данными «как есть» (именами файлов в большинстве случаев).

Mystray

можно тем же rename попробовать убрать все что не обычные символы: «s/\W/_/g» (только предварительно поиграйтесь на тестовом полигоне).

ILoveYAnny

Mystray: Слушайте, почти то, что нужно. Убирает все лишние символы, но и Кириллические символы тоже. Исправил команду вот так, «s/\w/_/g», остались только Кириллические символы, и иконки 🙁 Можно ли модифицировать команду так, что бы остались только Латинские/Кириллические символы без иконок?

Mystray

ILoveYAnny: Это pcre-выражение, как-нибудь типа «s/[^0-9a-zA-Z\-\._а-яА-Я]/_/g» (все, кроме указанных символов/диапахонов между [^ и ] )

ILoveYAnny

Mystray: Тааак почти получилось, все нужные символы остались, ненужные символы заменились на иконку чёрного ромба с вопросом, и в конце файла добавилось — «(неверная кодировка)», можно с этим что-нибудь сделать?
Обычные символы, которые НЕ входит в регулярку удалилось, однако эти иконки с сердечками и нотам, превратились в ромбы.

Mystray

ILoveYAnny

Mystray: Проблема в том, что такие символы могут быть разными и их может быть или не быть в большом массиве файлов. Сейчас попробую с кодировками поиграться..
Если использовать ls -b
Вот так этот символ выглядит до rename — ♥
А вот так после — \231\245
Что самое интересно, нашёл под Win инструмент, который убирает лишние символы, дак вот с именами, включающими такие символы, он работать не может..

Войдите, чтобы написать ответ

Как настроить2 сетевых интерфейса в Linux UBUNTU, с 2 разными шлюзами?

Источник

Оцените статью
Adblock
detector