Oleksandr Gavenko's blog
2017-02-09 23:50 Safe file prefix to be on top in a list

Putting one symbol prefix from the beginning of ASCII chart to file name bring that file up in a list of files ordered by names.

Here is the list of possible candidates:

Oct Dec Hex  Name
040  32 0x20 space
041  33 0x21 !, exclamation mark
042  34 0x22 ", double quote
043  35 0x23 #, hash
044  36 0x24 $, dollar
045  37 0x25 %, percent
046  38 0x26 &, ampersand
047  39 0x27 ', quote
050  40 0x28 (, open parenthesis
051  41 0x29 ), close parenthesis
052  42 0x2a *, asterisk
053  43 0x2b +, plus
054  44 0x2c ,, comma
055  45 0x2d -, minus
056  46 0x2e ., full stop
057  47 0x2f /, oblique stroke

/ is reserved by FS. Space is hard to see. Quoting characters require awful quoting.

! is used for history expansion by shells in interactive mode.

# at the beginning of word is comment syntax in shell.

$ used for variable substitution in shells.

& is command separator in Windows CMD and control operator in shells.

( and ) have special meaning in shells along with *.

*, ., + are special in regex.

- is used as marker of comand argument. Usage of special agreement to supply file list after -- or prefixing like ./- is common technique to allow - as file prefix.

% should be quoted in URL and have special meaning in Windows CMD and environment variables.

Dot is safe as prefix in file name but solely . and .. have special meaning for FS and it should be qouted in regex.

The winner is comma , although it is hard to distinguish. You may see comma as prefix in Lisp special backquote syntax.

Some tools uses comma as field separator. For example in Ant build tools this:

<fileset dir="." includes="**/*,*.xml"></fileset>

should be replaced with:

<fileset dir=".">
    <include name="**/*,*.xml" />

because , have special meaning when used in includes attribute.

Another pretty safe prefix is plus sign except that it require escaping in regex.

GNU Coreutils have utility that checks file names for safety:

$ cd $DIR
$ pathchk --portability **/*

List of reserved characters prohibited in file names.


OS X: Cross-platform filename best practices and conventions.


Filename on Windows.


Is it correct to use certain special characters when naming filenames in Linux?


What characters are safe in cross-platform file names for Linux, Windows and OS-X.

fs, naming


all / emacs / java / python


admin(1), anki(1), blog(1), css(2), cygwin(2), emacs(3), fs(1), git(1), hg(2), html(1), interview(11), java(1), js(3), lighttpd(1), mobile(1), naming(1), printer(1), problem(5), quiz(6), rst(1), security(1), sql(1), srs(1), unit(1), utils(1), vcs(1), web(2), win(2)