Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This question already has an answer here:

I have this file in my linux machine:

 ----------9976723563nneh4_-----192.9.200.4

I try to delete this file but I cant as all see here:

what need to add to rm in order to remove this file ?

rm "----------9976723563nneh4_-----192.9.200.4"
rm: illegal option -- --------9976723563nneh4_-----192.9.200.4
usage: rm [-fiRr] file ...

.

rm '----------9976723563nneh4_-----192.9.200.4'
rm: illegal option -- --------9976723563nneh4_-----192.9.200.4
usage: rm [-fiRr] file ...
share|improve this question

marked as duplicate by Michael Hampton, voretaq7 May 2 '13 at 17:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
From my point it will better to show this question , because rm is different from cd and –  yael May 2 '13 at 15:08

2 Answers 2

up vote 7 down vote accepted
rm -- ----------9976723563nneh4_-----192.9.200.4

You need -- in order to tell rm (and more or less all other GNU software) that all following parameters are file names even when beginning with "-". Otherwise (and in your case) the file name is confused with options. Another possibility is

rm ./----------9976723563nneh4_-----192.9.200.4

Edit 1

Calling this trivial answer a "great solution" makes me feel obliged to take it to a higher level. The basic problem cannot be solved "better" but you can try to get used to always making -- an argument. And some shell code (replacing rm by a shell function) can help you with this:

rm () {
  local args sep_found=no
  args=("$@")
  while [ $# -gt 0 ]; do
    if [ "--" = "$1" ]; then
      sep_found=yes
      break
    fi
    shift
  done
  if [ "yes" = "$sep_found" ]; then
    command rm "${args[@]}"
  else
    echo "WARNING: rm called without '--' seperator."
    echo "Please correct the command; aborting."
  fi
}

You would put this in e.g. ~/.bashrc.

share|improve this answer
    
GREAT SOLUTION _ WOW _ -:) –  yael May 2 '13 at 15:28
    
@yael See the edit. –  Hauke Laging May 2 '13 at 16:35

From the manual page for rm:

To remove a file whose name starts with a '-', for example '-foo', use one of these commands:

rm -- -foo

rm ./-foo

so to remove your file, try rm -- ----------9976723563nneh4_-----192.9.200.4.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.