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" />
</fileset>

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 **/*
https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words

List of reserved characters prohibited in file names.

https://support.apple.com/en-us/HT202808

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

https://msdn.microsoft.com/en-us/library/windows/desktop/aa368590.aspx

Filename on Windows.

http://unix.stackexchange.com/questions/155793/is-it-correct-to-use-certain-special-characters-when-naming-filenames-in-linux

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

http://superuser.com/questions/358855/what-characters-are-safe-in-cross-platform-file-names-for-linux-windows-and-os

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

fs, naming

Feeds

all / emacs / java / python

Tags

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

Archive