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?
Update:
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!!
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 01 '12 at 15:14