0

i have a file is name

-ksh.l.15092015.log

to delete this file i do this:

rm -rf -ksh.l.15092015.log

but i have this error:

rm: Not a recognized flag: k

Usage: rm [-firRe] [--] File...

i have do this:

rm -rf *ksh*

but i have the same errors, why ?

Thx for your help !

Mercer
  • 836
  • 5
  • 11
  • 22

2 Answers2

5

Execute this:

rm -rf ./-ksh.l.15092015.log
SHW
  • 14,786
  • 14
  • 66
  • 101
5

This is a nice question, and from what I remember some sysadmin interviews make use of it.

You have multiple ways of doing this:

  • Remove using relative or absolute path. As SHW has said in his answer:

    rm -rf ./-ksh.l.15092015.log
    

    or

    rm -rf /full/path/-ksh.l.15092015.log
    
  • Remove by disabling the interpretation of dash (-) for rm

    rm -- -ksh.l.15092015.log
    
  • And the more convoluted way :), using the inode:

    ls -li | grep ksh.l.15092015.log
    
    5383819 -rw-r--r-- 1 root root        0 sep 15 13:17 -ksh.l.15092015.log
    
    find . -inum 5383819 -delete
    

You could also use mc and vim, but these are the "shell" ways that I know.

primero
  • 590
  • 1
    "disabling the the shell interpretation of dash" — incorrect. The shell does not interpret that dash, it's the rm command that does it. – Celada Sep 15 '15 at 11:06