在 Linux 上查找名称中包含非法 Windows 字符的文件 [英] Find files with illegal windows characters in the name on Linux
问题描述
我的 Linux 机器上有一个项目,其中包含在 Windows 中被视为非法/保留字符的文件 (http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx).该项目在多个文件夹中有超过 10,000 个文件,我将确定这些文件的路径.
I have a projects on my Linux box that contains file with characters that are considered illegal/reserved in Windows (http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx). The project has over 10,000 files across several folders and I'll to identify the path for these files.
我可以找到.-name "*?*"
用于每个非法/保留字符,但是否有更简单的方法来查找包含 < 的所有文件?>:"/ | ? *
I can find . -name "*?*"
for each of the illegal/reserved characters, but is there an easier way to find all files that contain < > : " / | ? *
确定后,我想从每个文件中删除所有此类字符.
Once I've identified, I would like to remove all such characters from each of these files.
推荐答案
这个 find one-liner 应该适合你:
This find one-liner should work for you:
find . -name "*[<>:\|?*]*" -exec bash -c 'x="{}"; y="$(sed "s/[<>:\|?*]+/-/g" <<< "$x")" && mv "$x" "$y" ' ;
这篇关于在 Linux 上查找名称中包含非法 Windows 字符的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!