3

EDIT I've just found out that the file system on which this does not work appears to be cifs. So this is probably a file system issue.

FINAL EDIT With the help of our system admin, I could log onto the disk server. There, the command rm : worked. It's kind of annoying to require help from someone for such a task and this does not really answer the question. I still have no idea what was going on.

A related post that I found during my last searches and that I found relevant : How to delete this undeletable directory?


I accidentally created a file named : and I wish to delete it. However, the shell (bash) has a strange behavior, so I can't seem to manipulate the file. I could find its inode, but can't find what to do next. Could anyone help ? Thanks !

$ bash --version
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
[snip]
$ ls -l 
[snip]
-rw-r--r-- 1 user user  41086 Oct  5 13:50 :
$ rm :
rm: cannot remove ':': No such file or directory
$ rm -iv *
rm: remove regular file ':'? y
rm: cannot remove ':': No such file or directory
rm: remove regular file 'a.out'? ^C
$ touch :
$ ls -l 
[snip]
-rw-r--r-- 1 user user      0 Oct  5 14:13 :
-rw-r--r-- 1 user user      0 Oct  5 14:13 :
$ rm : ; ls -l
[snip]
-rw-r--r-- 1 user user  41086 Oct  5 13:50 :
$ stat -c '%n %i' *
: 17915935
[snip]
Tom-Tom
  • 165
  • 6
  • Can you add the output of command `grep $(whoami) /etc/passwd ; bash --version` to the topic? – Egor Vasilyev Oct 05 '17 at 12:25
  • What is the output of `LC_ALL=C ls`? If you're getting two files with the same name after a `touch`, then I'd guess either one of them _isn't_ named as it appears, or there is file system corruption. Given your symptoms, the latter seems a bit more likely (in which case a `fsck` in single-user mode may be a good idea) – Fox Oct 05 '17 at 12:54
  • your copy show file being trucated, also you mention cifs, maybe you can delete on server (if it is a distant cifs). – Archemar Oct 05 '17 at 13:03

4 Answers4

1

looks like macOS (:) was used as file delimitor as those time.

try

find . -inum 17915935 -print

If there is only one

find . -inum 17915935 -delete
Archemar
  • 31,183
  • 18
  • 69
  • 104
  • It does not work. There is only one file with inode `17915935` but `find . -inum 17915935 -delete` gives the result `find: cannot delete './:': No such file or directory`. Thanks anyway for your answer. – Tom-Tom Oct 05 '17 at 12:36
  • This is what caused me to write my answer -- the reason this isn't working is I believe find is calling `rm -f ./:` which spawns a new shell or something. – djsmiley2kStaysInside Oct 05 '17 at 13:42
  • 1
    @djsmiley2k It does not. – Kusalananda Oct 05 '17 at 14:56
0

If all the other suggestions fail, move all other contents of the directory out of the way and delete the directory itself from its parent directory using rm -rf directory_name.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
  • I have tried this, but it does not work. I have renamed the old directory and work now without the spurious file. But it is still there in a dead directory waiting for a proper death. Thank you ! – Tom-Tom Oct 06 '17 at 13:27
-1

Try

rm -rf "./\:"

The \ will escape the : from trying to do other things such as spawning a new shell, the ./ tells bash that you wish to do something to a file in the current directory.

Also, rm -rf "./:" and rm -rf "\:" may work depending on where the file has been created.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
djsmiley2kStaysInside
  • 1,326
  • 1
  • 10
  • 15
  • Thanks for your answer. Unfortunately, none of these solutions worked for me... – Tom-Tom Oct 06 '17 at 13:28
  • 1
    I would really really really advise against that. **Never** issue `-f` to any command when you are not sure what is going on, especially `rm` and even more with `-r`. In fact, I would recommend you to use `rm -i "./\:"` instead. – giusti Oct 09 '17 at 11:44
-3

could you please try

rm -f :

it's working for me

Romeo Ninov
  • 16,541
  • 5
  • 32
  • 44
Shyam Gupta
  • 101
  • 1