Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Before yesterday, I used only lower case letters, numbers, dot (.) and underscore(_) for directories and file naming.

Today I would like to start using more special characters. Which ones are safe (by safe I mean I will never have any problem)?

ps : I can't believe this question hasn't been asked already on this site, but I've searched for the word "naming" and read canonical questions without success (mosts are about computer names).

Edit #1 : (btw, I don't use upper case letters for file names. I don't remember why. But since a few month, I have production problems with upper case letters : Some OS do not support ascii!)

Here's what happened yesterday at work : As usual, I had to create a self signed SSL certificate. As usual, I used the name of the website for the files :

Then comes the problem : Generate a wildcard self signed certificate. I did that and named the files, which is misleading (it's a certificate for *

I came back home, started putting some stars in apache configuration files filenames and see if it works (on a useless home computer, not even stagging).

Stars in file names really scares me : Some coworkers/vendors/... can do some script using rm find xarg that would lead to, and already one answer talks about disaster.

Edit #2 :

Just figured that : does not need to be escaped. Anyone knows why it is not used in file names?

Edit #3 :

Let's summarize what I understood so far :

  • . and _ are safe to use in file names.
  • Special character that need to be escaped (eg space | ( * ) should be avoided.
  • Some other special caracters should be avoided for various reasons ( / - : )

What about all the other ones, like % or =?

share|improve this question

4 Answers 4

up vote 8 down vote accepted

Sounds like a recipe for disaster.

You can use anything other than / - but you might want to wrap in single quotes (') to avoid execution of special characters.

eg. $*`\|

Using special characters in file names is very much a Windows-ism - mostly taken from GUI machine administration versus command line (which doesn't lend itself to continuously having to escape file names).

The safest approach is just to stick to a-zA-Z0-9_.

share|improve this answer
Yes. It scares a lot. – user130370 Sep 27 '12 at 11:19
I assume dot(.) and underscores(_) are safe for file names. dash (-) is not. Are there any other character that can be safely used ? – user130370 Sep 27 '12 at 11:53
It all comes down to how you escape the file names. The safest approach is just to stick to [a-zA-Z0-9_.] – Ben Lessani - Sonassi Sep 27 '12 at 12:33
Do not use the pipe | character in filenames. – jftuga Sep 27 '12 at 13:09
Please read my answer to avoid any ambiguity or out of context comments. I had already stated the OP should restrict his filenames to a specific subset of characters [a-zA-Z0-9_.] - hypens NOT included. The original question was What characters can you not use - and the only one you can't use is / - anything else is fine. But advisable, no. – Ben Lessani - Sonassi Sep 27 '12 at 14:19

In UNIX you can use any character except '/' because it separates directory names. Unicode characters are also fine.

share|improve this answer
And NUL, since everything is C-based under the hood. – Ignacio Vazquez-Abrams Sep 27 '12 at 13:57

While Antonio is correct, my suggestion would be do not change your naming style, except maybe to add upper-case letters (but even that can be ambigous if other operating systems get into the mix).

This will spare you a lot of problems you might face otherwise with locales and special characters that might need to be escaped (like e.g. the space or $ sign) in shell commands.

share|improve this answer
Thank you very much. I'll update the question to provide more details. – user130370 Sep 27 '12 at 11:13

: is generally not used in file names because Windows would refuse reading such a file. It has more restrictions with names and in particular use : as a device separator, which Unix doesn't need having a single file system hierarchy.

share|improve this answer
On OS X, a file named ooz:bar would appear in the Finder as ooz/bar. – kojiro Sep 27 '12 at 16:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.