How do I prevent 'cd' command from going to home directory?

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











up vote
1
down vote

favorite












The thing is that sometimes I type 'cd' by mistake and that take me to the home directory.



e.g. I'm in a directory that have a hidden directory and a visible directory, I quickly press 'cd'+tab and that takes me to the home directory










share|improve this question







New contributor




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















  • 2




    If you cd somewhere by accident, use cd - to return to your previous location -- bash keeps the $OLDPWD variable for this purpose. See gnu.org/software/bash/manual/bash.html#index-cd
    – glenn jackman
    1 hour ago






  • 1




    If you truly want cd to do nothing, you can write a function named cd that does nothing when no arguments are given, otherwise call builtin cd "$@"
    – glenn jackman
    1 hour ago














up vote
1
down vote

favorite












The thing is that sometimes I type 'cd' by mistake and that take me to the home directory.



e.g. I'm in a directory that have a hidden directory and a visible directory, I quickly press 'cd'+tab and that takes me to the home directory










share|improve this question







New contributor




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















  • 2




    If you cd somewhere by accident, use cd - to return to your previous location -- bash keeps the $OLDPWD variable for this purpose. See gnu.org/software/bash/manual/bash.html#index-cd
    – glenn jackman
    1 hour ago






  • 1




    If you truly want cd to do nothing, you can write a function named cd that does nothing when no arguments are given, otherwise call builtin cd "$@"
    – glenn jackman
    1 hour ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











The thing is that sometimes I type 'cd' by mistake and that take me to the home directory.



e.g. I'm in a directory that have a hidden directory and a visible directory, I quickly press 'cd'+tab and that takes me to the home directory










share|improve this question







New contributor




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











The thing is that sometimes I type 'cd' by mistake and that take me to the home directory.



e.g. I'm in a directory that have a hidden directory and a visible directory, I quickly press 'cd'+tab and that takes me to the home directory







command-line






share|improve this question







New contributor




vinicius de novaes 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




vinicius de novaes 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






New contributor




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









asked 2 hours ago









vinicius de novaes

61




61




New contributor




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





New contributor





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






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







  • 2




    If you cd somewhere by accident, use cd - to return to your previous location -- bash keeps the $OLDPWD variable for this purpose. See gnu.org/software/bash/manual/bash.html#index-cd
    – glenn jackman
    1 hour ago






  • 1




    If you truly want cd to do nothing, you can write a function named cd that does nothing when no arguments are given, otherwise call builtin cd "$@"
    – glenn jackman
    1 hour ago












  • 2




    If you cd somewhere by accident, use cd - to return to your previous location -- bash keeps the $OLDPWD variable for this purpose. See gnu.org/software/bash/manual/bash.html#index-cd
    – glenn jackman
    1 hour ago






  • 1




    If you truly want cd to do nothing, you can write a function named cd that does nothing when no arguments are given, otherwise call builtin cd "$@"
    – glenn jackman
    1 hour ago







2




2




If you cd somewhere by accident, use cd - to return to your previous location -- bash keeps the $OLDPWD variable for this purpose. See gnu.org/software/bash/manual/bash.html#index-cd
– glenn jackman
1 hour ago




If you cd somewhere by accident, use cd - to return to your previous location -- bash keeps the $OLDPWD variable for this purpose. See gnu.org/software/bash/manual/bash.html#index-cd
– glenn jackman
1 hour ago




1




1




If you truly want cd to do nothing, you can write a function named cd that does nothing when no arguments are given, otherwise call builtin cd "$@"
– glenn jackman
1 hour ago




If you truly want cd to do nothing, you can write a function named cd that does nothing when no arguments are given, otherwise call builtin cd "$@"
– glenn jackman
1 hour ago










2 Answers
2






active

oldest

votes

















up vote
2
down vote













Use gedit ~/.bashrc and insert these lines at the bottom:





cd() 
[[ $# -eq 0 ]] && return
builtin cd "$@"



Open a new terminal and now when you type cd with no parameters you simply stay in the same directory.






share|improve this answer



























    up vote
    1
    down vote













    Here's how I put the current dir and user in my windows title - You can adapt it to your need, but cd -, equivalent to cd $OLDPWD is a better solution.



    From my ~/.bashrc:



    # from the "xttitle(1)" man page - put info in window title
    update_title()
    [[ $TERM = xterm-color ]] && xttitle "[$$] $USER@$HOSTNAME:$PWD"


    cd()

    [[ -z "$*" ]] && builtin cd $HOME
    [[ -n "$*" ]] && builtin cd "$*"
    update_title






    share|improve this answer




















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "89"
      ;
      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: true,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );






      vinicius de novaes is a new contributor. Be nice, and check out our Code of Conduct.









       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1086161%2fhow-do-i-prevent-cd-command-from-going-to-home-directory%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
      2
      down vote













      Use gedit ~/.bashrc and insert these lines at the bottom:





      cd() 
      [[ $# -eq 0 ]] && return
      builtin cd "$@"



      Open a new terminal and now when you type cd with no parameters you simply stay in the same directory.






      share|improve this answer
























        up vote
        2
        down vote













        Use gedit ~/.bashrc and insert these lines at the bottom:





        cd() 
        [[ $# -eq 0 ]] && return
        builtin cd "$@"



        Open a new terminal and now when you type cd with no parameters you simply stay in the same directory.






        share|improve this answer






















          up vote
          2
          down vote










          up vote
          2
          down vote









          Use gedit ~/.bashrc and insert these lines at the bottom:





          cd() 
          [[ $# -eq 0 ]] && return
          builtin cd "$@"



          Open a new terminal and now when you type cd with no parameters you simply stay in the same directory.






          share|improve this answer












          Use gedit ~/.bashrc and insert these lines at the bottom:





          cd() 
          [[ $# -eq 0 ]] && return
          builtin cd "$@"



          Open a new terminal and now when you type cd with no parameters you simply stay in the same directory.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 20 mins ago









          WinEunuuchs2Unix

          37.8k1060139




          37.8k1060139






















              up vote
              1
              down vote













              Here's how I put the current dir and user in my windows title - You can adapt it to your need, but cd -, equivalent to cd $OLDPWD is a better solution.



              From my ~/.bashrc:



              # from the "xttitle(1)" man page - put info in window title
              update_title()
              [[ $TERM = xterm-color ]] && xttitle "[$$] $USER@$HOSTNAME:$PWD"


              cd()

              [[ -z "$*" ]] && builtin cd $HOME
              [[ -n "$*" ]] && builtin cd "$*"
              update_title






              share|improve this answer
























                up vote
                1
                down vote













                Here's how I put the current dir and user in my windows title - You can adapt it to your need, but cd -, equivalent to cd $OLDPWD is a better solution.



                From my ~/.bashrc:



                # from the "xttitle(1)" man page - put info in window title
                update_title()
                [[ $TERM = xterm-color ]] && xttitle "[$$] $USER@$HOSTNAME:$PWD"


                cd()

                [[ -z "$*" ]] && builtin cd $HOME
                [[ -n "$*" ]] && builtin cd "$*"
                update_title






                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  Here's how I put the current dir and user in my windows title - You can adapt it to your need, but cd -, equivalent to cd $OLDPWD is a better solution.



                  From my ~/.bashrc:



                  # from the "xttitle(1)" man page - put info in window title
                  update_title()
                  [[ $TERM = xterm-color ]] && xttitle "[$$] $USER@$HOSTNAME:$PWD"


                  cd()

                  [[ -z "$*" ]] && builtin cd $HOME
                  [[ -n "$*" ]] && builtin cd "$*"
                  update_title






                  share|improve this answer












                  Here's how I put the current dir and user in my windows title - You can adapt it to your need, but cd -, equivalent to cd $OLDPWD is a better solution.



                  From my ~/.bashrc:



                  # from the "xttitle(1)" man page - put info in window title
                  update_title()
                  [[ $TERM = xterm-color ]] && xttitle "[$$] $USER@$HOSTNAME:$PWD"


                  cd()

                  [[ -z "$*" ]] && builtin cd $HOME
                  [[ -n "$*" ]] && builtin cd "$*"
                  update_title







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 50 mins ago









                  waltinator

                  21.1k74168




                  21.1k74168




















                      vinicius de novaes is a new contributor. Be nice, and check out our Code of Conduct.









                       

                      draft saved


                      draft discarded


















                      vinicius de novaes is a new contributor. Be nice, and check out our Code of Conduct.












                      vinicius de novaes is a new contributor. Be nice, and check out our Code of Conduct.











                      vinicius de novaes is a new contributor. Be nice, and check out our Code of Conduct.













                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1086161%2fhow-do-i-prevent-cd-command-from-going-to-home-directory%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Comments

                      Popular posts from this blog

                      What does second last employer means? [closed]

                      Installing NextGIS Connect into QGIS 3?

                      One-line joke