What characters should be restricted from a Unix file name? What characters should be restricted from a Unix file name? unix unix

What characters should be restricted from a Unix file name?


The minimum are slash ('/') and NULL ('\0')


Firstly, what you're describing is black listing. Your better option is to white list your characters, as it is easier (from a user perspective) to have characters inserted rather than taken away.

In terms of what would be good in a unix environment:

  • a-z
  • A-Z
  • 0-9
  • underscore (_)
  • dash (-)
  • period (.)

Should cover your basics. Spaces can be okay, but make things difficult. Windows users love them, unix/linux don't. So depending on your target audience choose accordingly.


Although the accepted answer might have truth I think there's a benefit to having some restrictions that could be potentially annoying for scripting or other stuff:

  • forward slash (/)
  • backslash (\)
  • NULL (\0)
  • tick (`)
  • starts with a dash (-)
  • star (*)
  • pipes (|)
  • semicolon (;)
  • quotations (" or ')
  • colon (:)

( - maybe space though I'm reluctant to add that.)

As you can see you might just be better off whitelisting as @Gavin suggests...