3

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 ...
yael
  • 2,433
  • 5
  • 31
  • 43
  • From my point it will better to show this question , because rm is different from cd and – yael May 02 '13 at 15:08

2 Answers2

8
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.

Hauke Laging
  • 5,285
  • 2
  • 24
  • 40
1

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.

Flup
  • 7,978
  • 2
  • 32
  • 43