Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was under the impression that the only character not allowed in file names was /, but I don't seem to be able to create a file whose name contains characters such as *, \, ", :, |, < or > either. For instance,

$ echo "*"
> *
$ touch "*"
> touch: setting times of `*': No such file or directory

I'm writing a shell script that requires the user to type a file name and I would like to make sure the name doesn't have any invalid characters. Is there a list somewhere?


I didn't realise I was doing this in a FAT32 filesystem (USB stick), which does not allow `*' and other characters in file names. No wonder it didn't work. Sorry, my bad!!

share|improve this question
Which characters are allowed or disallowed depends on the filesystem in use. – Jim Paris Oct 1 '12 at 2:51
@JimParis Do you have an example of a *nix filesystem that doesn't allow characters other than \0 and /? – jordanm Oct 1 '12 at 4:43
Also interesting in this context: Understanding Unix file name encoding – Marco Oct 1 '12 at 7:07
@JimParis you were right. – Ernest A C Oct 1 '12 at 13:27
"I'm writing a shell script that requires the user to type a file name and I would like to make sure the name doesn't have any invalid characters. Is there a list somewhere?" Just try to create the file, and fail cleanly and tell them if it didn't work. There are other reasons file creation could fail (creating under a nonexistent directory, for example), and trying to check for all of them in advance just opens you to a race condition. – Random832 Oct 1 '12 at 15:14
up vote 3 down vote accepted

I'm pretty sure the only reserved bytes are 0 (ASCII Nul) and 0x2f (ASCII '/', forward slash).

You can easily make a file with '.', '\' and other funky things in it. Think "unicode file names", which contain all kinds of weird byte values.

Naturally, you can't have duplicate file names in the same directory, so files named "." and ".." can't usually be made by a mere user: the filesystem part of the kernel creates them when a directory gets created.

Also note that most filesystems have a limit on the length of a file name, and you can't create a file whose name is the empty string.

share|improve this answer

Well actually you could, just make it a single quote,

e.g touch '*'

Or use your FM:

enter image description here

For more details, see the Reserved characters and words on this page, at least / \ . .. are not allowed

share|improve this answer
Interesting, with single quotes works. What is wrong with the double quotes? (nice icons btw :) – Ernest A C Oct 1 '12 at 0:03
They stop the shell from treating meta-characters differently. mywiki.wooledge.org/Quotes – llua Oct 1 '12 at 0:44
@llua But the echo "*" command showed that the shell wasn't treating * specially within double quotes. Something odd is going on here. – Kyle Jones Oct 1 '12 at 2:23
@llua @don_crissti Yes, the double quotes should prevent the * from being treated especially, just like single quotes. – Ernest A C Oct 1 '12 at 13:21
It wasn't the quotes but the filesystem (FAT32) which does not allow `*' in file names. Mystery solved! – Ernest A C Oct 1 '12 at 13:26

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.