Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The answer is that you can't, unless your filesystem has a bug. Here's why:</p> <p>There is a system call for renaming your file defined in <code>fs/namei.c</code> called <code>renameat</code>:</p> <pre><code>SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname, int, newdfd, const char __user *, newname) </code></pre> <p>When the system call gets invoked, it does a path lookup (<code>do_path_lookup</code>) on the name. Keep tracing this, and we get to <code>link_path_walk</code> which has this:</p> <pre><code>static int link_path_walk(const char *name, struct nameidata *nd) { struct path next; int err; unsigned int lookup_flags = nd-&gt;flags; while (*name=='/') name++; if (!*name) return 0; ... </code></pre> <p>This code applies to any file system. What's this mean? It means that if you try to pass a parameter with an actual <code>'/'</code> character as the name of the file using traditional means, it will not do what you want. There is no way to escape the character. If a filesystem "supports" this, it's because they either:</p> <ul> <li>Use a unicode character or something that <em>looks</em> like a slash but isn't.</li> <li>They have a bug.</li> </ul> <p>Furthermore, if you <em>did</em> go in and edit the bytes to add a slash character into a file name, bad things would happen. That's because you could never refer to this file by name :( since anytime you did, Linux would assume you were referring to a nonexistent directory. Using the 'rm *' technique would not work either, since bash simply expands that to the filename. Even <code>rm -rf</code> wouldn't work, since a simple strace reveals how things go on under the hood (shortened):</p> <pre><code>$ ls testdir myfile2 out $ strace -vf rm -rf testdir ... unlinkat(3, "myfile2", 0) = 0 unlinkat(3, "out", 0) = 0 fcntl(3, F_GETFD) = 0x1 (flags FD_CLOEXEC) close(3) = 0 unlinkat(AT_FDCWD, "testdir", AT_REMOVEDIR) = 0 ... </code></pre> <p>Notice that these calls to <code>unlinkat</code> would fail because they need to refer to the files by name.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload