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

E.g.

mv ./-fiJjJX1c2A.jpg lvEnkpdgmLM.jpg

...