+4 votes
in Operating Systems by (71.8k points)

When I use 'mv' command to rename a file that starts with '-', it gives an error. How can I rename the file?

mv -fiJjJX1c2A.jpg lvEnkpdgmLM.jpg

mv: invalid option -- 'J'

Try 'mv --help' for more information.

1 Answer

+1 vote
by (353k points)
selected by
Best answer

When you use the dash '-' followed by an alphabet, the system thinks that you provided an option for the command.

Use forward slash ('/') in front of the dash ('-').  Since the forward slash is an escape sequence character, the system will not consider the dash ('-') as an option of the command.


mv ./-fiJjJX1c2A.jpg lvEnkpdgmLM.jpg