简体   繁体   English

Linux重命名不在utf-8中的多个文件

[英]Linux rename multiple files that are not in utf-8

I have old samba server files that does not show special characters like ä,ö,ü,õ in file names. 我有旧的samba服务器文件,在文件名中没有显示诸如ä,ö,ü,õ之类的特殊字符。 They are showed as ? 它们显示为? mark. 标记。 Because of that my clients cannot open those files or folders. 因此,我的客户无法打开这些文件或文件夹。 They see the files and folders, but their names are blank. 他们看到文件和文件夹,但名称为空。 In server they are showed like this: T??tunnid.doc for example. 在服务器中,它们显示如下:例如T ?? tunnid.doc。

Once I rename them with mv command, then my clients can open the folders and files with no problems. 使用mv命令重命名它们之后,我的客户端即可mv打开文件夹和文件。

Does anyone know any script that I can use to rename all the files that have ? 有谁知道我可以用来重命名所有具有的所有文件的脚本吗? mark in them. 在其中标记。 So they show - instead. 所以他们显示-相反。 I would like to rename the files in specific folder for example /samba/documents/... 我想重命名特定文件夹中的文件,例如/ samba / documents / ...

You can try to use convmv which rename files changing it character encoding. 您可以尝试使用convmv来重命名更改其字符编码的文件。 Usually this symbols ? 通常这个符号? says about different encoding of filenames and terminal/filesystem/something else. 谈到有关文件名和终端/文件系统/其他内容的不同编码。 Try to determine which character encoding your files use and run it like this: 尝试确定文件使用的编码字符,然后像这样运行它:

convmv -fcp1251 -tutf8 *

You can write simple script or just shell loop to iterate over directories and rename all needed files: 您可以编写简单的脚本,也可以编写shell循环来遍历目录并重命名所有需要的文件:

find /full/path -execdir convmv --notest -fcp1251 -tutf8 {} \;

But first be sure you use correct character encoding. 但是首先请确保使用正确的字符编码。

我不是100%肯定会成功,所以我需要一些构想。

find . -type d -name '*?*' -execdir rename '?' '_' {} \;

I checked the rename command and I think it would work 我检查了重命名命令,我认为它将起作用

rename "s/[^A-Za-z0-9-_]/_/g"

But how can I add a directory to it. 但是,如何向其添加目录。 So it only checks that directory not the whole ubuntu. 因此,它仅检查该目录,而不检查整个ubuntu。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM