Home > Net >  ultimative find command in bash to trace all illegal and unknown chars and symbols in filenames
ultimative find command in bash to trace all illegal and unknown chars and symbols in filenames

Time:11-07

Many similar solutions can be found to detect or change "illegal" characters in filenames. Most solutions require you to know the illegal characters. A solution to find those filenames often ends with something like:

find . -name "*[\ \;\"\\\=\?\~\<\>\&\*\|\$\'\,\{\}\%\^\#\:\(\)]*"

This is already quite good, but sometimes there are cryptic characters (e.g. h͔͉̝e̻̦l̝͍͓l̢͚̻o͇̝̘w̙͇͜o͔̼͚r̝͇̞l̘̘d̪͔̝.̟͔̠t͉͖̼x̟̞t̢̝̦ or ʇxʇ.pʅɹoʍoʅʅǝɥ or © or €), symbols, or characters from other character sets in my file names. I can not trace these files this way. Inverse lookarounds or the find command with regex is probably the right approach, but I don't get anywhere.

In other words: Find all filenames which do NOT match the following pattern [^a-zA-Z0-9 ._-] would be perfect. Mostly [:alnum:] but with regex the command would be more flexibel.

find . ! -name [^a-zA-Z0-9 ._-] does not do the job. Any idea?

I use bash or zsh on OSX.

CodePudding user response:

You can try

find . -name '*[!a-zA-Z0-9 ._-]*'
  • Related