I accidentally created a file named “-C” on one of my Linux servers when using the tar command. I was hitting my head against the wall for a while trying to work out how to use the mv command to rename the file to something more meaningful.
The problem is that the command line thinks that the “-C” is an option for the mv command, so you’ll keep getting an error like this:
-bash-3.2# mv -C archive.tgz mv: invalid option -- C Try `mv --help' for more information.
Even if you try and use quotes or the escape character it will still process the characters after the dash as an option to the command.
The solution is to tell the command that you have finished passing arguments by using double dash (“–“). Alternatively you can also use the full path to the file or “./-C”
-bash-3.2# mv -- -C archive.tgz -bash-3.2#
Hopefully this will help someone else who is looking to rename a file starting with “-“.