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.

12
  • 5
    POSIX forbids "/" and NULL in filenames ;)
    – Rinzwind
    Jan 11, 2016 at 20:38
  • 1
    Oh and if you want to delete it: use the inode to reference the file
    – Rinzwind
    Jan 11, 2016 at 20:41
  • 1
    Sounds like a very elaborate approach to avoid learning how to configure your server :/
    – Tyler
    Jan 11, 2016 at 22:35
  • 2
    @ParanoidPanda What is this "lock down mode" you speak of? I'm not aware of any such feature on Ubuntu...
    – Cyle
    Jan 11, 2016 at 22:49
  • 1
    Next thing you'll be trying to put in a file name is a real live bamboo shoot ;)
    – user2121
    Jan 11, 2016 at 22:59

3 Answers 3

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.

6
  • 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, 2016 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, 2016 at 19:02
  • @ParanoidPanda superuser.com/q/603792/427197
    – kos
    Jan 11, 2016 at 19:03
  • 4
    @ParanoidPanda that would make the filesystem incomptatible with POSIX ;-)
    – Rinzwind
    Jan 11, 2016 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, 2016 at 22:54
0

In the Mac OS terminal, you can replace the slash with a colon (:) when you're renaming, and when you view the file in Finder (graphic file manager) the file name should have the slash at the place you typed a colon. This probably also works in Linux.

1
  • 2
    Have you actually tested this on Linux?
    – muru
    Jun 9, 2022 at 8:41
-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).

2
  • 1
    Could provide the unicode substitute to use?
    – user364819
    Jan 11, 2016 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. Jan 12, 2016 at 0:59

You must log in to answer this question.