Find files with illegal Windows characters in a name on Linux

I have projects on my Linux box that contains a file with characters that are considered illegal / reserved on Windows ( http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx ). The project has over 10,000 files in several folders, and I will determine the path for these files.

I can find . -name "*\?*" find . -name "*\?*" for each of the illegal / reserved characters, but is there an easier way to find all files containing < > : " / \ | ? *

As soon as I determined, I would like to remove all such characters from each of these files.

+6
source share
3 answers

This will find a single line file for you:

 find . -name "*[<>:\\|?*]*" -exec bash -c 'x="{}"; y="$(sed "s/[<>:\\|?*]\+/-/g" <<< "$x")" && mv "$x" "$y" ' \; 
+9
source

fnmatch pattern allows you to specify characters in [] as follows:

 find . -name '*[<>:/\\|?*]*' 
+9
source

None of the answers above find files or directories that end in either space ('') or period / period ('.'), Which are also not visible in the Win32 API.

By adding @falsetru's answer to .eg, you could do

 find . -name '*[<>:/\\|?*]*' -o -name '*[ \.]' 
0
source

Source: https://habr.com/ru/post/954612/


All Articles