How to remove a file starting with hyphen "-"

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 4, 5, 6, 7

Issue

  • Remove a file starting with Hyphen -
$ rm -test
rm: invalid option -- 't'

Resolution

  • To remove a file starting with - , for example -test, please use one of these commands:
#  rm -- -test
 # rm ./-test

Root Cause

  • Hyphen is used to specify options in most commands. A file with it's name starts with "-" can mislead the command's inteperation. As per rm man page, commands provided in resolution above can be applied to remove such files.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments