3

I've somehow created a file that I can not seem to figure out how to delete via CLI.

$ ls -alF total 8195 -rw-r--r--+ 1 me my_group 0 Jul 19 14:10 ''$'\r' drwxrwx---+ 1 system system 0 Nov 17 14:58 ./ drwxr-xr-x+ 1 system system 0 Jul 17 15:40 ../ ... 

The first line item here I can not seem to find the correct escape sequence to be able to delete.

Attempting to grep this entry does not even work properly:

$ ls -alF | head -n2 total 8195 -rw-r--r--+ 1 me my_group 0 Jul 19 14:10 

Note that when grepping / using other pipe'd commands, I can never see the name of the file.

this is a Cygwin wrapped Win10 environment

1

2 Answers 2

3

Two suggestions:

  1. Run ls -li to get the inode, then use find to delete it.

    ls -li foo 42 -rw-r--r--. 1 user group 0 Nov 17 15:07 foo 

If the inode was 42, as in the above example, run: find . -inum 42 -exec rm -i {} \;, which will interactively prompt you to remove the file.

  1. Run rm -i ? ?? ??? to have the shell expand to the one, two, and three-character filenames in the current directory; one of them will appear to be blank, and is probably the file in question; simply answer "no" to the prompts to remove the files you want to keep.
2
  • I've used linux for years.. Never knew you could print inode info with ls, and also did not know that bash expands ?'s. Perfect answer, both solutions worked as expected. Commented Nov 17, 2017 at 20:17
  • the 1st one looks more reliable Commented Nov 17, 2017 at 20:28
0

I tried creating a file with the same name as yours and I was able to delete it with rm every time. Do you know which version of rm you have installed? Perhaps the version you have is buggy? I assume you tried simply putting the name inside double quotes. If not, give that a try.

In the case that dosen't work, I'd suggest you try using rm with some wildcards. Move all other files out of the folder and just run the following.

rm -f "*"

That only failed me once, when the file filesystem itself was corrupt, and fsck didn't touch it. I honestly just left the file there until the next time I reformatted it.

2
  • Again, this is a Win10 env wrapped in Cygwin, so there could be differences there. rm (GNU coreutils) 8.26 || Packaged by Cygwin (8.26-2) Commented Nov 17, 2017 at 20:38
  • Interesting that Cygwin actually has a newer version of coreutils then I do. Have you tried deleting the file using only escape sequences? Like, rm $(echo -e "<escape sequences here>"). Perhaps specifying each character by code would work. Commented Nov 17, 2017 at 20:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.