Find files with illegal windows characters in the name on Linux

后端 未结 3 777
清酒与你
清酒与你 2020-12-08 09:26

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.8

相关标签:
3条回答
  • 2020-12-08 09:30

    Neither of the answers above finds files or directories that ended in either space (' ') or period/dot ('.') which are also not visible with Win32 API.

    Adding to .e.g @falsetru's answer, one could do

    find . -name '*[<>:/\\|?*]*' -o -name '*[ \.]'
    
    0 讨论(0)
  • 2020-12-08 09:40

    fnmatch pattern allow you to specify that characters in [] as follow:

    find . -name '*[<>:/\\|?*]*'
    
    0 讨论(0)
  • 2020-12-08 09:47

    This find one-liner should work for you:

    find . -name "*[<>:\\|?*]*" -exec bash -c 'x="{}"; y="$(sed "s/[<>:\\|?*]\+/-/g" <<< "$x")" && mv "$x" "$y" ' \;
    
    0 讨论(0)
提交回复
热议问题