1

On a shared machine somehow a directory ; (with a lot of stuff in it) was created.

I only have shell access to this machine and so I can't use any GUI File explorer to delete that file.

rm -rf ;

results in strange behavior since the semicolon probably acts as a command separator and is not evaluated as the directory's name.

rm -rf ./; rm: refusing to remove '.' or '..' directory: skipping './'

rm: refusing to remove '.' or '..' directory: skipping './'

Furthermore I do not want to delete other directories and so I am not willing to play around with wildcards and stuff.

How can I securely remove that semicolon-directory recursivly?

h0ch5tr4355
  • 125
  • 6

2 Answers2

5

Quote its name. Quoting the name will stop the shell from interpreting it as a command terminator.

rm -rf ';'

The same goes for working with files with names containing other characters that the shell usually treat specially, like filename globbing characters, &, <, >, (, ), {, }, newlines, tabs, spaces, etc., and any other character that may be part of the shell's grammar.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
  • 2
    More on that at [How to use a special character as a normal one in Unix shells?](//unix.stackexchange.com/q/296141) – Stéphane Chazelas Jul 07 '22 at 13:51
  • I was sure this would be a dup but my search-foo failed me – roaima Jul 07 '22 at 13:55
  • OK. Thanks. I solved it with `find . -name "*;*" -exec rm -rf {} \;` now. But yours work too. I think I tried this and it didnt work but I could produce it now with `mkdir ';'` – h0ch5tr4355 Jul 07 '22 at 14:17
0

when I have a hard time deleting a directory I download the tool mc(midnight commander), it's a tool that is very similar to Norton Commander and has great functions and GUI that you can use to delete problematic directories

try

yum install mc -y 

in the command line after the installation write just

mc
Daniel
  • 50
  • 4