Bash – How to create a file with the name specified in ASCII encoding

bashfilenames

I want to create a file that is called ascii 007, which is the bell symbol, which is not printable. I tried nano $'\007', but that just created a file called ?; cat ? print the test content, that I placed in the file.

So how do I create a file, with a name set by the ascii encoding and not plainly spelled out?

Best Answer

Everything has probably actually worked as you expected, but you have been misled by two different phenomena:

  • ls and some other utilities display ? for non-printable characters by default
  • ? is a glob that matches a single character

That results in the following behaviour:

$ echo foo > $'\007'
$ ls
?
$ cat ?
foo

So it seems like we have a file that is literally named ?, right? Actually, that's just a happy coincidence of the two above phenomena -- the file is still called ^G:

$ printf '<%q>\n' *
<$'\a'>
$ ls -lb
total 0
-rw-r--r-- 1 chris chris 0 Aug  1 14:20 \a

Probably everything worked as you expected, despite what immediately appeared to indicate that the file was literally called ?.

Related Question