silk
silk

Reputation: 35

Cannot find file to delete via git bash, but it shows up in file explorer

I started to learn git yesterday, and I made a mistake when I created ssh key as the first image shows.

create file img

I tried .bat delete way and dos del command, still cannot delete file named cd ..
The prompt said cannot find file. The attribute of file size is 0 byte.

file in explorer

How to delete this file?

Upvotes: 0

Views: 2114

Answers (2)

VonC
VonC

Reputation: 1328712

I managed to delete "cd .." in a CMD Windows with <path/to/git>\latest\usr\bin in %PATH%. That gives me access to rm.exe.

vonc@VONCAVN7 C:\test
> where rm
D:\prgs\git\latest\usr\bin\rm.exe

I had:

vonc@VONCAVN7 C:\test
> dir /x
 Volume in drive C is test

 Directory of C:\test

08/08/2017  07:11    <DIR>                       .
08/08/2017  07:11    <DIR>                       ..
08/08/2017  07:11                 0              cd ..

With that, I typed:

vonc@VONCAVN7 C:\test
> rm cd*

And the file cd .. was gone

As commented by eryksun,

rm.exe isn't a Linux app. It uses msys-2.0.dll, which links with Windows API functions from kernel32.dll and native NT system calls from ntdll.dll.
In this case it's how it bypasses the Windows API to make direct system calls that solves the problem: NtOpenFile (open the directory to list it and the "cd .." file to delete it), NtQueryDirectoryFile (list the directory), and NtSetInformationFile (set the file's delete disposition).


As eryksun commented, the pure Windows syntax (meaning, it does not need a Git Linux-like command like rm) would have worked too:

del "\\?\C:\test\cd .."

See "What does \\?\ mean when prepended to a file path".
That will disable all string parsing and send the string that follows it straight to the file system.

Upvotes: 3

Ayushya
Ayushya

Reputation: 10447

Look into the properties of the file. There you may find file location. Go to that location and delete from there.

And see which type of file is it. I mean, it may be a system file, and if it is, system will not allow you to delete it. Open explorer as administrator and then try deleting it.

Upvotes: 0

Related Questions