Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What characters should be restricted from a Unix file name?

Consider a Save As dialog with a free text entry where the user enters a file name as free text, then clicks a Save button. The software then validates the file name, and saves the file if the name is valid.

On a Unix file system, what rules should be applied in the validation such that:

  • The name will not be difficult to manipulate later in terms of escaping special characters, etc.
  • The rules are not so restrictive that saving a file becomes non-user-friendly.

So basically, what is the minimum set of characters that should be restricted from a Unix file name?

like image 298
barrymc Avatar asked Jan 19 '09 15:01

barrymc


People also ask

What characters are not allowed in Unix filenames?

Under Linux and other Unix-related systems, there are only two characters that cannot appear in the name of a file or directory, and those are NUL '\0' and slash '/' .

Which special character should be avoided during naming a file in Unix?

You cannot use the null character. No need to use . (dot) in a filename. Some time dot improves readability of filenames.


2 Answers

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

like image 188
mouviciel Avatar answered Sep 24 '22 17:09

mouviciel


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.

like image 35
3 revs, 2 users 78% Avatar answered Sep 24 '22 17:09

3 revs, 2 users 78%