I've somehow created a file called
\ in a directory (yes, backslash character). I've tried all sorts of sed, find and grep fu but I just can't delete it! I know I could just delete the directory, but is there a more interesting way to fix this?
Can you be sure that that really is just a backslash?
Thought the following rather amusing session may prove useful to others in a similarly dismayed state as I just was:
[root@x y]# ls -la . | grep -F '\' -rw-r--r-- 1 root root 452 Jun 17 10:28 \ [root@x y]# rm \\ rm: cannot remove '\': No such file or directory [root@x y]# rm '\' rm: cannot remove '\': No such file or directory [root@x y]# for f in *; do echo "#$f#"; done; # # #file1# #file2# [root@x y]# mv ' ' x [root@x y]# vim x
FYI, the content appeared to be a dump of awk environment variables.. currently no idea how it got there!
If you are not sure to master the command line for this operation, I suggest installing Midnight Commander, or
mc, see https://midnight-commander.org/
(I am not affiliated with it, just a happy user of it). It is packaged in various Linux distributions.
It is a small utility showing a graphical display (but still just with a terminal, no X/Window) of your files, with all standard operations available, like delete.
It can simplify things, as it will be quicker just to move to the file with the arrows and press F8 (if memory serves) to delete the file.