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 : www2.example.com.key www2.example.com.crt www2.example.com.csr.

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

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 http://www.ucs.cam.ac.uk/support/unix-support/misc/horror, 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 =?

4 Answers 4


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_.

  • Yes. It scares a lot.
    – user130370
    Sep 27, 2012 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, 2012 at 11:53
  • 1
    It all comes down to how you escape the file names. The safest approach is just to stick to [a-zA-Z0-9_.] Sep 27, 2012 at 12:33
  • 1
    Do not use the pipe | character in filenames.
    – jftuga
    Sep 27, 2012 at 13:09
  • 1
    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. Sep 27, 2012 at 14:19

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


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.

  • Thank you very much. I'll update the question to provide more details.
    – user130370
    Sep 27, 2012 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.

  • On OS X, a file named ooz:bar would appear in the Finder as ooz/bar.
    – kojiro
    Sep 27, 2012 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy