You are not logged in.

#1 2011-01-13 16:23:42

jocom
Member
Registered: 2009-04-29
Posts: 74

Creating weird filenames

Hi all,

After I read this article, http://www.dwheeler.com/essays/fixing-u … names.html (with which I actually agree in most points), I wondered how one can create files with such weird names.
I tried a lot, but did not succeed in it.

I am interested in this, because I am writing a php script that will parse user input to "ls". Allthough I guess I will just forbid all weird filenames and restrict them to the Portable Filename Character Set, I still was interested (just for the heck of it).

I guess such things can be done with C quite easily, but is it possible with Bash? Have any of you ever experimented with black arts like this?

Eager to know about your dirty hacks smile
jocom

Offline

#2 2011-01-13 16:30:45

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

Re: Creating weird filenames

I've accidentally made filenames with newlines in before. It's a pain when you don't realise you've done it tongue
My friend has a Mac, and for some godforsaken reason that lets him make files with slashes in the name.

Offline

#3 2011-01-13 16:33:21

jocom
Member
Registered: 2009-04-29
Posts: 74

Re: Creating weird filenames

Barrucadu wrote:

I've accidentally made filenames with newlines in before.

So how did you do that?

Offline

#4 2011-01-13 16:35:23

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

Re: Creating weird filenames

touch "hello
"

Quotes can be evil >.>

Offline

#5 2011-01-13 16:41:17

jocom
Member
Registered: 2009-04-29
Posts: 74

Re: Creating weird filenames

Ok, that worked smile

Allthough "ls" displays it as '?', but "echo *" displays a nice blank line.
But how about other metacharacters? I guess they are harder...

jocom

Offline

#6 2011-01-13 17:23:42

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Creating weird filenames

'touch "?foo"' works here. Just experiment a bit.

Offline

#7 2011-01-13 17:41:11

sisco311
Member
From: Romania
Registered: 2008-05-23
Posts: 112

Re: Creating weird filenames

jocom wrote:

Ok, that worked smile

Allthough "ls" displays it as '?', but "echo *" displays a nice blank line.
But how about other metacharacters? I guess they are harder...

jocom

> $(echo -e bell:'\007')

don't drink unwashed fruit juice.
i never make predictions, especially about the future.

Offline

#8 2011-01-13 17:54:27

jocom
Member
Registered: 2009-04-29
Posts: 74

Re: Creating weird filenames

karol wrote:

'touch "?foo"' works here. Just experiment a bit.

True. That one is not very hard. Nor is the space: "touch \ ". I did not yet find a way for getting the \t tab character in a filename.

But the harder ones, in my eyes are control characters 1-31 or 127.

Offline

#9 2011-01-13 17:58:53

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Creating weird filenames

Tab:

[karol@black bbb]$ touch "$(echo -e "ab\tc")"
[karol@black bbb]$ ls
ab?c
[karol@black bbb]$ ls -b
ab\tc
[karol@black bbb]$ echo *
ab    c

Last edited by karol (2011-01-13 18:01:57)

Offline

#10 2011-01-13 18:13:38

jocom
Member
Registered: 2009-04-29
Posts: 74

Re: Creating weird filenames

Hmz, I am getting the hang of it. You can even input the filenames by hitting (Ctrl-V) (Ctrl-x), where x denotes some control character. For example

$ touch foo^Hbar # Ctrl-V Ctrl-H gives the ^H
$ echo *
fobar

So in the output the second 'o' of "foobar" is 'backspaced' {huge grin}!

Offline

#11 2011-01-13 18:27:57

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Creating weird filenames

'ls --show-control-chars' should be equal to 'echo *'

[karol@black bbb]$ ls --show-control-chars
fobar
[karol@black bbb]$ ls --quoting-style=literal
foo?bar
[karol@black bbb]$ ls --quoting-style=escape
foo\bbar

From the ls man page:
       --quoting-style=WORD
              use quoting style WORD for entry names: literal, locale, shell, shell-always, c, escape

Offline

#12 2011-01-13 20:02:01

olive
Member
From: Belgium
Registered: 2008-06-22
Posts: 1,490

Re: Creating weird filenames

You can specify any character in bash by the following syntax $'\xHH' (HH is the hexadecimal code of the character). Some specific syntax are also supported.

Some funny file names
touch beep$'\x07'

give a file name with a beep in it (echo * will give you an audible beep; ls seems to filter these funny characters).

touch Hello$'\n'World

give a file name with a newline in it (again visible by echo *).

Last edited by olive (2011-01-13 20:02:47)

Offline

#13 2011-01-14 18:07:04

jocom
Member
Registered: 2009-04-29
Posts: 74

Re: Creating weird filenames

This is fun! I indeed recognized the beeping filename smile

So what is the best 'filename hack' that you guys can think of?

I thought of ETX or EOT characters in filenames, but it did not give funny results with 'echo *'.

What do you think?
jocom

Offline

Board footer

Powered by FluxBB