4

I understand that this will likely break and confuse the hell out of my system, but is it possible to name or rename a file so that it has /s in its name (this is needed for a file which needs to go to an equally crazy server - well, sort of, it's more of a crazy workaround)? I am running Ubuntu GNOME 15.10 with GNOME 3.18, and I have tried to do this with most programs, and they either make a folder with the file because they treat what is before the / as the folder and what is after it as the file name, or just give me an error.

Reason:

The specific reason why I need it is because I set up a server which is stubborn and now won't change it's mind about where its config file is. However I accidentally put a / in the name of the file so it believes that the config file rather being in ~/configuration/files/config1.conf is in ~/configuration/files/con/fig1.conf... So you might say that I should just create a folder in files and call it con and then have the config file called fig1.conf, however the server doesn't even currently allow the creation of new directories or anything really... So I think that my only hope is going to be to put the forward slash in the file name for now until it goes out of its lock down mode.

| improve this question | |
9

Is it possible to name or rename a file so that it has /s in its name [...]?

No, it's not, for obvious reasons.

E.g. consider you have a directory containing:

  • a directory named "foo" containing a file named "bar"
  • a file named "foo/bar"
/path/to/foo/bar # file named "bar" in the directory named "foo"
/path/to/foo/bar # file named "foo/bar"

Referencing either of the two would be ambiguous.

If you're curious as to where the limitation is imposed, that's at the kernel level, in order to comply with the filesystem's specifications.

In general, any character can be used in a filename aside from / (unicode 002f) and \0 (unicode 0000), and filenames such as . and .. are disallowed as well.

| improve this answer | |
  • And what would happen if I got a file with a forward slash in the name from another filesystem and put it onto my machine? – user364819 Jan 11 '16 at 18:58
  • And is there now way at all of bypassing this and putting a file there? I mean, what if I loaded if off a LiveUSB onto the machine while the machine was not on but the disk mounted? – user364819 Jan 11 '16 at 19:02
  • 4
    @ParanoidPanda that would make the filesystem incomptatible with POSIX ;-) – Rinzwind Jan 11 '16 at 20:15
  • 1
    @ParanoidPanda If the file does indeed have a / in its name on the underlying file system I can imagine one of two possible outcomes. Either a programmer was paranoid about corrupted data coming back from the file system and reported this as an error. Or the / would be visible all the way through to user mode. However that would only make the file name visible. Any attempt to stat the file to get more information or open it would cause the kernel to parse the file name and interpret the / as a directory separator. Hence you would not be able to access the file, even if you can see it – kasperd Jan 11 '16 at 22:54
-1

It CAN be done, not easily, not well, and not recommended (it creates problems when trying to remove the file.

Simply use a unicode substitute. It's better explained at linuxanswers.com.

bash shell example using the unicode "fractional slash" U+2044

bash# >test$'\xe2\x88\x95'file
bash# ls --show-control-chars
test∕file
bash# ls
test???file

I don't know if however the server can then access the file, but Ubuntu can. You may have to alias it at the server end, if possible. (Haven't had to touch a Windows installation since the days of Windows 95).

| improve this answer | |
  • 1
    Could provide the unicode substitute to use? – user364819 Jan 11 '16 at 21:14
  • 5
    This won't actually help the OP, since their "server" is expecting an actual ASCII slash, not a Unicode character that just happens to look like a slash. – Ilmari Karonen Jan 12 '16 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy