How do you escape “-” in a command in the Shell (Zsh)? [on hold]












0















I am trying to rename a file named "-a" to "a" using the command line (zsh shell). I have tried the following



mv -a "a"
mv '-a' "a"
mv "-a" "a"


but got



mv: illegal option -- a
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory


each time. Is there a way to escape "-a" or any other command option in the shell?










share|improve this question









New contributor




Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Terrance, Pilot6, Florian Diesch, dessert, N0rbert 4 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Terrance, Pilot6, Florian Diesch, dessert, N0rbert

If this question can be reworded to fit the rules in the help center, please edit the question.












  • 1





    How is this question related to Ubuntu?

    – Pilot6
    5 hours ago











  • Just updated the question

    – Deepak Kumar
    5 hours ago











  • The question is off-topic here and will be closed soon.

    – Pilot6
    5 hours ago











  • Why cat, grep and other commands can't understand files starting with minus sign?

    – steeldriver
    5 hours ago











  • I believe that the comments above are suggesting that this should be posted in unix.stackexchange.com instead of on this site (if you were wondering where else you could go for help)

    – Jeff
    5 hours ago
















0















I am trying to rename a file named "-a" to "a" using the command line (zsh shell). I have tried the following



mv -a "a"
mv '-a' "a"
mv "-a" "a"


but got



mv: illegal option -- a
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory


each time. Is there a way to escape "-a" or any other command option in the shell?










share|improve this question









New contributor




Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Terrance, Pilot6, Florian Diesch, dessert, N0rbert 4 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Terrance, Pilot6, Florian Diesch, dessert, N0rbert

If this question can be reworded to fit the rules in the help center, please edit the question.












  • 1





    How is this question related to Ubuntu?

    – Pilot6
    5 hours ago











  • Just updated the question

    – Deepak Kumar
    5 hours ago











  • The question is off-topic here and will be closed soon.

    – Pilot6
    5 hours ago











  • Why cat, grep and other commands can't understand files starting with minus sign?

    – steeldriver
    5 hours ago











  • I believe that the comments above are suggesting that this should be posted in unix.stackexchange.com instead of on this site (if you were wondering where else you could go for help)

    – Jeff
    5 hours ago














0












0








0








I am trying to rename a file named "-a" to "a" using the command line (zsh shell). I have tried the following



mv -a "a"
mv '-a' "a"
mv "-a" "a"


but got



mv: illegal option -- a
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory


each time. Is there a way to escape "-a" or any other command option in the shell?










share|improve this question









New contributor




Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I am trying to rename a file named "-a" to "a" using the command line (zsh shell). I have tried the following



mv -a "a"
mv '-a' "a"
mv "-a" "a"


but got



mv: illegal option -- a
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory


each time. Is there a way to escape "-a" or any other command option in the shell?







command-line bash zsh






share|improve this question









New contributor




Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 5 hours ago







Deepak Kumar













New contributor




Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 5 hours ago









Deepak KumarDeepak Kumar

62




62




New contributor




Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Deepak Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by Terrance, Pilot6, Florian Diesch, dessert, N0rbert 4 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Terrance, Pilot6, Florian Diesch, dessert, N0rbert

If this question can be reworded to fit the rules in the help center, please edit the question.







put on hold as off-topic by Terrance, Pilot6, Florian Diesch, dessert, N0rbert 4 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Terrance, Pilot6, Florian Diesch, dessert, N0rbert

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 1





    How is this question related to Ubuntu?

    – Pilot6
    5 hours ago











  • Just updated the question

    – Deepak Kumar
    5 hours ago











  • The question is off-topic here and will be closed soon.

    – Pilot6
    5 hours ago











  • Why cat, grep and other commands can't understand files starting with minus sign?

    – steeldriver
    5 hours ago











  • I believe that the comments above are suggesting that this should be posted in unix.stackexchange.com instead of on this site (if you were wondering where else you could go for help)

    – Jeff
    5 hours ago














  • 1





    How is this question related to Ubuntu?

    – Pilot6
    5 hours ago











  • Just updated the question

    – Deepak Kumar
    5 hours ago











  • The question is off-topic here and will be closed soon.

    – Pilot6
    5 hours ago











  • Why cat, grep and other commands can't understand files starting with minus sign?

    – steeldriver
    5 hours ago











  • I believe that the comments above are suggesting that this should be posted in unix.stackexchange.com instead of on this site (if you were wondering where else you could go for help)

    – Jeff
    5 hours ago








1




1





How is this question related to Ubuntu?

– Pilot6
5 hours ago





How is this question related to Ubuntu?

– Pilot6
5 hours ago













Just updated the question

– Deepak Kumar
5 hours ago





Just updated the question

– Deepak Kumar
5 hours ago













The question is off-topic here and will be closed soon.

– Pilot6
5 hours ago





The question is off-topic here and will be closed soon.

– Pilot6
5 hours ago













Why cat, grep and other commands can't understand files starting with minus sign?

– steeldriver
5 hours ago





Why cat, grep and other commands can't understand files starting with minus sign?

– steeldriver
5 hours ago













I believe that the comments above are suggesting that this should be posted in unix.stackexchange.com instead of on this site (if you were wondering where else you could go for help)

– Jeff
5 hours ago





I believe that the comments above are suggesting that this should be posted in unix.stackexchange.com instead of on this site (if you were wondering where else you could go for help)

– Jeff
5 hours ago










2 Answers
2






active

oldest

votes


















2














When you need to specify a file name that starts with a dash as argument to a command, which might interpret it as option instead, you can write the absolute or explicit relative path to the file instead:



mv /path/to/-a a
mv ./-a a


Alternatively some (not all) commands support -- as separator between options and positional arguments. This depends on the specific command you use though.



mv -- -a a





share|improve this answer































    1














    mv -- -a a


    The '--' tells the shell that what follows after this is not an option to the command.



    All your variants give, after the evaluation of quotes and backslash, the command mv -a a so you are told that the option '-a' is not a valid option to the mv command and that you should give a target operand.






    share|improve this answer
































      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      When you need to specify a file name that starts with a dash as argument to a command, which might interpret it as option instead, you can write the absolute or explicit relative path to the file instead:



      mv /path/to/-a a
      mv ./-a a


      Alternatively some (not all) commands support -- as separator between options and positional arguments. This depends on the specific command you use though.



      mv -- -a a





      share|improve this answer




























        2














        When you need to specify a file name that starts with a dash as argument to a command, which might interpret it as option instead, you can write the absolute or explicit relative path to the file instead:



        mv /path/to/-a a
        mv ./-a a


        Alternatively some (not all) commands support -- as separator between options and positional arguments. This depends on the specific command you use though.



        mv -- -a a





        share|improve this answer


























          2












          2








          2







          When you need to specify a file name that starts with a dash as argument to a command, which might interpret it as option instead, you can write the absolute or explicit relative path to the file instead:



          mv /path/to/-a a
          mv ./-a a


          Alternatively some (not all) commands support -- as separator between options and positional arguments. This depends on the specific command you use though.



          mv -- -a a





          share|improve this answer













          When you need to specify a file name that starts with a dash as argument to a command, which might interpret it as option instead, you can write the absolute or explicit relative path to the file instead:



          mv /path/to/-a a
          mv ./-a a


          Alternatively some (not all) commands support -- as separator between options and positional arguments. This depends on the specific command you use though.



          mv -- -a a






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 5 hours ago









          Byte CommanderByte Commander

          65.1k27178300




          65.1k27178300

























              1














              mv -- -a a


              The '--' tells the shell that what follows after this is not an option to the command.



              All your variants give, after the evaluation of quotes and backslash, the command mv -a a so you are told that the option '-a' is not a valid option to the mv command and that you should give a target operand.






              share|improve this answer






























                1














                mv -- -a a


                The '--' tells the shell that what follows after this is not an option to the command.



                All your variants give, after the evaluation of quotes and backslash, the command mv -a a so you are told that the option '-a' is not a valid option to the mv command and that you should give a target operand.






                share|improve this answer




























                  1












                  1








                  1







                  mv -- -a a


                  The '--' tells the shell that what follows after this is not an option to the command.



                  All your variants give, after the evaluation of quotes and backslash, the command mv -a a so you are told that the option '-a' is not a valid option to the mv command and that you should give a target operand.






                  share|improve this answer















                  mv -- -a a


                  The '--' tells the shell that what follows after this is not an option to the command.



                  All your variants give, after the evaluation of quotes and backslash, the command mv -a a so you are told that the option '-a' is not a valid option to the mv command and that you should give a target operand.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 5 hours ago

























                  answered 5 hours ago









                  mucluxmuclux

                  2,3141725




                  2,3141725















                      Popular posts from this blog

                      Category:香港粉麵

                      List *all* the tuples!

                      Channel [V]