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

# is comment syntax in a shell.

$ used for variable substitution in shells.

& is a command separator in Windows CMD and a 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 from the dot sign. You may see comma as a prefix in a Lisp special backquote syntax.

Some tools use 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 the plus sign except that it requires 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


adb(1), admin(1), android(1), anki(1), ansible(2), aop(1), blog(2), bytecode(1), c(1), css(2), cygwin(2), driver(1), emacs(3), fs(1), git(3), google(1), gradle(1), hardware(1), hg(2), html(1), interview(13), java(4), js(3), lang(2), lighttpd(1), markdown(1), mobile(1), naming(1), oracle(1), print(1), problem(5), python(1), quiz(6), rst(2), security(3), spring(2), sql(2), srs(1), style(1), tls(2), txt(1), unit(1), utils(1), vcs(3), web(2), win(2), windows(1)