Best practice for naming files and directories


In Unix, filenames can generally be up to 255 characters long and contain any character except / and nul

However just because you can use most any character, it doesn't mean it's a good idea to do so.

Also in general, filenames are case sensitive, e.g the following two files are different.


You can also use multiple .'s in filenames. e.g it is quite common to see something like


Unix doesn't really have the filename extension concept that Windows does. It is more a convention. As such, you aren't restricted to three characters for the extension, you don't even need one or you can use more e.g


  The Issues

It is all too common to see files with spaces in their name e.g

My Document.txt
At first glance this may seem fairly innocuous. However this is a common source of problems when working from the shell. When working with such files you need to generally do one of two things

Quote the filename

'My Document.txt'
or escape the space
My\ Document.txt
This gets tired real quick.

There are a host of other characters that can cause similar issues, including &, ! and '

  The Solution

The solution is simple, stick to a small subset of the allowed characters.

POSIX even defines such a set here.

It boils down to


I would also suggest to just stick to lower case (unless there's a good reason for upper). Also avoid starting names with a -