Monday, July 12, 2010

Finding "illegal" filenames within *nix/OSX

So, this might seem quite obvious to some, but it took me a bit of searching and manual reading to work out.

Say I'm preparing a Mac File Share to copy over to a Windows File Share... In the process I know that Mac allows a bunch of characters that are illegal within Windows (such as * ? / \ | etc...).  What I want to do is track down every filename/directory that is going to cause my file copy to fail.

So the obvious command would be something along the lines of:

find . -name \\
when I want to find a filename with a \ in it.  OK fair enough this works fine.for most of those characters.  However I found that when I used ? or * in the search path, I regularly got returned results that I was not expecting (ie. All files/folders or Single Character files)... So whats the trick?  Really really simple, just use an extra \ to escape the search term.  So for example:

find . -name \*\\*\* will find any filename with a * in it.  Simple, but frustratingly difficult to discover!

Hope that helps someone a bit of time in future

No comments: