+4 votes
in Operating Systems by (15.3k 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

0 votes
by (27.1k points)

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