Files that begin with a hyphen (dash) can be tricky to remove because Linux or Unix will interpret the character after the dash as an option. For example, if the user attempts to type the following command, they would receive the error also shown below.

mv -myfile.txt myfile.txt

mv: invalid option – m Try `mv –help’ for more information.

In the example above, the operating system is interpreting the -m as a switch. For this mv command to work, you can prefix the source file name with its pathname.

mv ./-myfile.txt myfile.txt

Typing this command with the forward slash in front of the dash, renames the file in the current directory, causing Linux to ignore the dash. The forward slash is an escape sequence character that treats the dash only as text and not as part of the command.

  • Linux mv command help.
  • See our dash and hyphen pages for further information and links.
  • Linux help and support.