How do I use shell commands with a directory that contains '-' like '-78059735'?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I have an external program that generates directories with strings that are negative integers. I am trying to use basic shell commands including cd and ls with this directory, for example:



cd -78059735



Understandably, this fails because this looks like command line options starting with -7.




-bash: cd: -7: invalid option




Similarly, these variations also fail:



cd "-78059735"
cd "-78059735"
cd '-78059735'
cd '-78059735'
cd -78059735


How do I interact with this troublesome directory through the shell?










share|improve this question

























    up vote
    1
    down vote

    favorite












    I have an external program that generates directories with strings that are negative integers. I am trying to use basic shell commands including cd and ls with this directory, for example:



    cd -78059735



    Understandably, this fails because this looks like command line options starting with -7.




    -bash: cd: -7: invalid option




    Similarly, these variations also fail:



    cd "-78059735"
    cd "-78059735"
    cd '-78059735'
    cd '-78059735'
    cd -78059735


    How do I interact with this troublesome directory through the shell?










    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have an external program that generates directories with strings that are negative integers. I am trying to use basic shell commands including cd and ls with this directory, for example:



      cd -78059735



      Understandably, this fails because this looks like command line options starting with -7.




      -bash: cd: -7: invalid option




      Similarly, these variations also fail:



      cd "-78059735"
      cd "-78059735"
      cd '-78059735'
      cd '-78059735'
      cd -78059735


      How do I interact with this troublesome directory through the shell?










      share|improve this question













      I have an external program that generates directories with strings that are negative integers. I am trying to use basic shell commands including cd and ls with this directory, for example:



      cd -78059735



      Understandably, this fails because this looks like command line options starting with -7.




      -bash: cd: -7: invalid option




      Similarly, these variations also fail:



      cd "-78059735"
      cd "-78059735"
      cd '-78059735'
      cd '-78059735'
      cd -78059735


      How do I interact with this troublesome directory through the shell?







      bash shell escape-characters






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 41 mins ago









      mattm

      1114




      1114




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote













          It is because the command cd treats the character followed by - as valid option flag for it to work. Since 7 is not a valid one for cd it is failing with the error you are seeing.



          In such cases you can specify end of command line options by doing a double dash before the command name -- as below. The below command implies that the command line options for cd are complete and there are no other flags expected after --



          cd -- -78059735/


          You can even have other flags provided before -- which would work just fine. The below command for mkdir which takes an option -p to create a directory if it does not exist before works just fine with a string having -, provided you give an end of command line options flag right after -p



          mkdir -p -- /tmp/-78059735
          ls -d /tmp/*
          /tmp/-78059735


          rm command to delete a directory also works just fine as below



          rm -vrf -- /tmp/-78059735
          removed directory '/tmp/-78059735'





          share|improve this answer





























            up vote
            2
            down vote













            cd ./-78059735
            ls ./-78059735


            It works for me.






            share|improve this answer










            New contributor




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

















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "106"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476180%2fhow-do-i-use-shell-commands-with-a-directory-that-contains-like-78059735%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              3
              down vote













              It is because the command cd treats the character followed by - as valid option flag for it to work. Since 7 is not a valid one for cd it is failing with the error you are seeing.



              In such cases you can specify end of command line options by doing a double dash before the command name -- as below. The below command implies that the command line options for cd are complete and there are no other flags expected after --



              cd -- -78059735/


              You can even have other flags provided before -- which would work just fine. The below command for mkdir which takes an option -p to create a directory if it does not exist before works just fine with a string having -, provided you give an end of command line options flag right after -p



              mkdir -p -- /tmp/-78059735
              ls -d /tmp/*
              /tmp/-78059735


              rm command to delete a directory also works just fine as below



              rm -vrf -- /tmp/-78059735
              removed directory '/tmp/-78059735'





              share|improve this answer


























                up vote
                3
                down vote













                It is because the command cd treats the character followed by - as valid option flag for it to work. Since 7 is not a valid one for cd it is failing with the error you are seeing.



                In such cases you can specify end of command line options by doing a double dash before the command name -- as below. The below command implies that the command line options for cd are complete and there are no other flags expected after --



                cd -- -78059735/


                You can even have other flags provided before -- which would work just fine. The below command for mkdir which takes an option -p to create a directory if it does not exist before works just fine with a string having -, provided you give an end of command line options flag right after -p



                mkdir -p -- /tmp/-78059735
                ls -d /tmp/*
                /tmp/-78059735


                rm command to delete a directory also works just fine as below



                rm -vrf -- /tmp/-78059735
                removed directory '/tmp/-78059735'





                share|improve this answer
























                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  It is because the command cd treats the character followed by - as valid option flag for it to work. Since 7 is not a valid one for cd it is failing with the error you are seeing.



                  In such cases you can specify end of command line options by doing a double dash before the command name -- as below. The below command implies that the command line options for cd are complete and there are no other flags expected after --



                  cd -- -78059735/


                  You can even have other flags provided before -- which would work just fine. The below command for mkdir which takes an option -p to create a directory if it does not exist before works just fine with a string having -, provided you give an end of command line options flag right after -p



                  mkdir -p -- /tmp/-78059735
                  ls -d /tmp/*
                  /tmp/-78059735


                  rm command to delete a directory also works just fine as below



                  rm -vrf -- /tmp/-78059735
                  removed directory '/tmp/-78059735'





                  share|improve this answer














                  It is because the command cd treats the character followed by - as valid option flag for it to work. Since 7 is not a valid one for cd it is failing with the error you are seeing.



                  In such cases you can specify end of command line options by doing a double dash before the command name -- as below. The below command implies that the command line options for cd are complete and there are no other flags expected after --



                  cd -- -78059735/


                  You can even have other flags provided before -- which would work just fine. The below command for mkdir which takes an option -p to create a directory if it does not exist before works just fine with a string having -, provided you give an end of command line options flag right after -p



                  mkdir -p -- /tmp/-78059735
                  ls -d /tmp/*
                  /tmp/-78059735


                  rm command to delete a directory also works just fine as below



                  rm -vrf -- /tmp/-78059735
                  removed directory '/tmp/-78059735'






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 24 mins ago

























                  answered 30 mins ago









                  Inian

                  2,945822




                  2,945822






















                      up vote
                      2
                      down vote













                      cd ./-78059735
                      ls ./-78059735


                      It works for me.






                      share|improve this answer










                      New contributor




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





















                        up vote
                        2
                        down vote













                        cd ./-78059735
                        ls ./-78059735


                        It works for me.






                        share|improve this answer










                        New contributor




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



















                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          cd ./-78059735
                          ls ./-78059735


                          It works for me.






                          share|improve this answer










                          New contributor




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









                          cd ./-78059735
                          ls ./-78059735


                          It works for me.







                          share|improve this answer










                          New contributor




                          Gounou 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 answer



                          share|improve this answer








                          edited 18 mins ago





















                          New contributor




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









                          answered 31 mins ago









                          Gounou

                          663




                          663




                          New contributor




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





                          New contributor





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






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



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476180%2fhow-do-i-use-shell-commands-with-a-directory-that-contains-like-78059735%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              Long meetings (6-7 hours a day): Being “babysat” by supervisor

                              Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                              Confectionery