-bash: /bin/cd: No such file or directory - automatically execute ls after cd

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











up vote
6
down vote

favorite
1












I accidentially destroyed my cd command.



I tried to automatically execute ls after cd is called.



I found a post saying that I have to execute alias cd='/bin/cd && /bin/ls', but now I get -bash: /bin/cd: No such file or directory and can't change directoy anymore.







share|improve this question

















  • 16




    There is no /bin/cd; cd is a shell built-in.
    – Andy Dalton
    Jun 25 at 14:32










  • Enjoy unix.stackexchange.com/questions/354123 and what it hyperlinks to M. Dalton. (-:
    – JdeBP
    Jun 25 at 14:41






  • 3




    A POSIX compliant platform has a /bin/cd, but that only exists for formal reasons and is not usable for anything.
    – schily
    Jun 25 at 14:41






  • 1




    Wow /bin/cd must be the most useless command.
    – ctrl-alt-delor
    Jun 25 at 17:15










  • cd isn't a file on disk, It's a shell built-in command:type cd
    – PersianGulf
    Jun 25 at 17:26















up vote
6
down vote

favorite
1












I accidentially destroyed my cd command.



I tried to automatically execute ls after cd is called.



I found a post saying that I have to execute alias cd='/bin/cd && /bin/ls', but now I get -bash: /bin/cd: No such file or directory and can't change directoy anymore.







share|improve this question

















  • 16




    There is no /bin/cd; cd is a shell built-in.
    – Andy Dalton
    Jun 25 at 14:32










  • Enjoy unix.stackexchange.com/questions/354123 and what it hyperlinks to M. Dalton. (-:
    – JdeBP
    Jun 25 at 14:41






  • 3




    A POSIX compliant platform has a /bin/cd, but that only exists for formal reasons and is not usable for anything.
    – schily
    Jun 25 at 14:41






  • 1




    Wow /bin/cd must be the most useless command.
    – ctrl-alt-delor
    Jun 25 at 17:15










  • cd isn't a file on disk, It's a shell built-in command:type cd
    – PersianGulf
    Jun 25 at 17:26













up vote
6
down vote

favorite
1









up vote
6
down vote

favorite
1






1





I accidentially destroyed my cd command.



I tried to automatically execute ls after cd is called.



I found a post saying that I have to execute alias cd='/bin/cd && /bin/ls', but now I get -bash: /bin/cd: No such file or directory and can't change directoy anymore.







share|improve this question













I accidentially destroyed my cd command.



I tried to automatically execute ls after cd is called.



I found a post saying that I have to execute alias cd='/bin/cd && /bin/ls', but now I get -bash: /bin/cd: No such file or directory and can't change directoy anymore.









share|improve this question












share|improve this question




share|improve this question








edited Jun 26 at 11:01
























asked Jun 25 at 14:26









Black

4932728




4932728







  • 16




    There is no /bin/cd; cd is a shell built-in.
    – Andy Dalton
    Jun 25 at 14:32










  • Enjoy unix.stackexchange.com/questions/354123 and what it hyperlinks to M. Dalton. (-:
    – JdeBP
    Jun 25 at 14:41






  • 3




    A POSIX compliant platform has a /bin/cd, but that only exists for formal reasons and is not usable for anything.
    – schily
    Jun 25 at 14:41






  • 1




    Wow /bin/cd must be the most useless command.
    – ctrl-alt-delor
    Jun 25 at 17:15










  • cd isn't a file on disk, It's a shell built-in command:type cd
    – PersianGulf
    Jun 25 at 17:26













  • 16




    There is no /bin/cd; cd is a shell built-in.
    – Andy Dalton
    Jun 25 at 14:32










  • Enjoy unix.stackexchange.com/questions/354123 and what it hyperlinks to M. Dalton. (-:
    – JdeBP
    Jun 25 at 14:41






  • 3




    A POSIX compliant platform has a /bin/cd, but that only exists for formal reasons and is not usable for anything.
    – schily
    Jun 25 at 14:41






  • 1




    Wow /bin/cd must be the most useless command.
    – ctrl-alt-delor
    Jun 25 at 17:15










  • cd isn't a file on disk, It's a shell built-in command:type cd
    – PersianGulf
    Jun 25 at 17:26








16




16




There is no /bin/cd; cd is a shell built-in.
– Andy Dalton
Jun 25 at 14:32




There is no /bin/cd; cd is a shell built-in.
– Andy Dalton
Jun 25 at 14:32












Enjoy unix.stackexchange.com/questions/354123 and what it hyperlinks to M. Dalton. (-:
– JdeBP
Jun 25 at 14:41




Enjoy unix.stackexchange.com/questions/354123 and what it hyperlinks to M. Dalton. (-:
– JdeBP
Jun 25 at 14:41




3




3




A POSIX compliant platform has a /bin/cd, but that only exists for formal reasons and is not usable for anything.
– schily
Jun 25 at 14:41




A POSIX compliant platform has a /bin/cd, but that only exists for formal reasons and is not usable for anything.
– schily
Jun 25 at 14:41




1




1




Wow /bin/cd must be the most useless command.
– ctrl-alt-delor
Jun 25 at 17:15




Wow /bin/cd must be the most useless command.
– ctrl-alt-delor
Jun 25 at 17:15












cd isn't a file on disk, It's a shell built-in command:type cd
– PersianGulf
Jun 25 at 17:26





cd isn't a file on disk, It's a shell built-in command:type cd
– PersianGulf
Jun 25 at 17:26











3 Answers
3






active

oldest

votes

















up vote
23
down vote



accepted










Your system (like many Unix systems) does not have an external cd command (at least not at that path). Even if it had one, the ls would give you the directory listing of the original directory. An external command can never change directory for the calling process (your shell)1.



Remove the alias from the environment with unalias cd (and also remove its definition from any shell initialization files that you may have added it to).



With a shell function, you can get it to work as cd ordinarily does, with an extra invocation of ls at the end if the cd succeeded:



cd () 
command cd "$@" && ls -lah



or,



cd () command cd "$@" && ls -lah; 


This would call the cd command built into your shell with the same command line arguments that you gave the function. If the change of directory was successful, the ls would run.



The command command stops the shell from executing the function recursively.



The function definition (as written above) would go into your shell's startup file. With bash, this might be ~/.bashrc. The function definition would then be active in the next new interactive shell session. If you want it to be active now, then execute the function definition as-is at the interactive shell prompt, which will define it within your current interactive session.




1 On systems where cd is available as an external command, this command also does not change directory for the calling process. The only real use for such a command is to provide POSIX compliance and for acting as a test of whether changing directory to a particular one would be possible.






share|improve this answer























  • Where do I have to put the function?
    – Black
    Jun 25 at 14:37






  • 1




    @Black You may put it wherever you would have put the alias definition. In a bash shell, that would probably be in ~/.bashrc.
    – Kusalananda
    Jun 25 at 14:38











  • I added the function to ~/.bashrc but it does not work. ls -lah is not executed at all.
    – Black
    Jun 25 at 14:41










  • @Black No, you add it exactly the way I wrote it. Then it will be active in any new shell session.
    – Kusalananda
    Jun 25 at 14:41







  • 1




    Note that POSIXly, you'd use cd() command cd "$@" && ls -lah; , though that wouldn't work with zsh except in sh emulation. Not all shells have a builtin builtin. In ksh93, it does something different.
    – Stéphane Chazelas
    Jun 25 at 16:30

















up vote
7
down vote













I was able to solve it by removing the alias again with unalias cd






share|improve this answer























  • If you remove the stuck-out text, then this is the only answer that answers the question.
    – ctrl-alt-delor
    Jun 25 at 17:18






  • 1




    @ctrl-alt-delor Note there's no question in the question. We could only guess what the implicit question is. In this situation "why?" is as good as "how to revert?"
    – Kamil Maciorowski
    Jun 26 at 10:26

















up vote
5
down vote













That happened because:



$ type cd

cd is a shell builtin





share|improve this answer





















    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%2f451778%2fbash-bin-cd-no-such-file-or-directory-automatically-execute-ls-after-cd%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    23
    down vote



    accepted










    Your system (like many Unix systems) does not have an external cd command (at least not at that path). Even if it had one, the ls would give you the directory listing of the original directory. An external command can never change directory for the calling process (your shell)1.



    Remove the alias from the environment with unalias cd (and also remove its definition from any shell initialization files that you may have added it to).



    With a shell function, you can get it to work as cd ordinarily does, with an extra invocation of ls at the end if the cd succeeded:



    cd () 
    command cd "$@" && ls -lah



    or,



    cd () command cd "$@" && ls -lah; 


    This would call the cd command built into your shell with the same command line arguments that you gave the function. If the change of directory was successful, the ls would run.



    The command command stops the shell from executing the function recursively.



    The function definition (as written above) would go into your shell's startup file. With bash, this might be ~/.bashrc. The function definition would then be active in the next new interactive shell session. If you want it to be active now, then execute the function definition as-is at the interactive shell prompt, which will define it within your current interactive session.




    1 On systems where cd is available as an external command, this command also does not change directory for the calling process. The only real use for such a command is to provide POSIX compliance and for acting as a test of whether changing directory to a particular one would be possible.






    share|improve this answer























    • Where do I have to put the function?
      – Black
      Jun 25 at 14:37






    • 1




      @Black You may put it wherever you would have put the alias definition. In a bash shell, that would probably be in ~/.bashrc.
      – Kusalananda
      Jun 25 at 14:38











    • I added the function to ~/.bashrc but it does not work. ls -lah is not executed at all.
      – Black
      Jun 25 at 14:41










    • @Black No, you add it exactly the way I wrote it. Then it will be active in any new shell session.
      – Kusalananda
      Jun 25 at 14:41







    • 1




      Note that POSIXly, you'd use cd() command cd "$@" && ls -lah; , though that wouldn't work with zsh except in sh emulation. Not all shells have a builtin builtin. In ksh93, it does something different.
      – Stéphane Chazelas
      Jun 25 at 16:30














    up vote
    23
    down vote



    accepted










    Your system (like many Unix systems) does not have an external cd command (at least not at that path). Even if it had one, the ls would give you the directory listing of the original directory. An external command can never change directory for the calling process (your shell)1.



    Remove the alias from the environment with unalias cd (and also remove its definition from any shell initialization files that you may have added it to).



    With a shell function, you can get it to work as cd ordinarily does, with an extra invocation of ls at the end if the cd succeeded:



    cd () 
    command cd "$@" && ls -lah



    or,



    cd () command cd "$@" && ls -lah; 


    This would call the cd command built into your shell with the same command line arguments that you gave the function. If the change of directory was successful, the ls would run.



    The command command stops the shell from executing the function recursively.



    The function definition (as written above) would go into your shell's startup file. With bash, this might be ~/.bashrc. The function definition would then be active in the next new interactive shell session. If you want it to be active now, then execute the function definition as-is at the interactive shell prompt, which will define it within your current interactive session.




    1 On systems where cd is available as an external command, this command also does not change directory for the calling process. The only real use for such a command is to provide POSIX compliance and for acting as a test of whether changing directory to a particular one would be possible.






    share|improve this answer























    • Where do I have to put the function?
      – Black
      Jun 25 at 14:37






    • 1




      @Black You may put it wherever you would have put the alias definition. In a bash shell, that would probably be in ~/.bashrc.
      – Kusalananda
      Jun 25 at 14:38











    • I added the function to ~/.bashrc but it does not work. ls -lah is not executed at all.
      – Black
      Jun 25 at 14:41










    • @Black No, you add it exactly the way I wrote it. Then it will be active in any new shell session.
      – Kusalananda
      Jun 25 at 14:41







    • 1




      Note that POSIXly, you'd use cd() command cd "$@" && ls -lah; , though that wouldn't work with zsh except in sh emulation. Not all shells have a builtin builtin. In ksh93, it does something different.
      – Stéphane Chazelas
      Jun 25 at 16:30












    up vote
    23
    down vote



    accepted







    up vote
    23
    down vote



    accepted






    Your system (like many Unix systems) does not have an external cd command (at least not at that path). Even if it had one, the ls would give you the directory listing of the original directory. An external command can never change directory for the calling process (your shell)1.



    Remove the alias from the environment with unalias cd (and also remove its definition from any shell initialization files that you may have added it to).



    With a shell function, you can get it to work as cd ordinarily does, with an extra invocation of ls at the end if the cd succeeded:



    cd () 
    command cd "$@" && ls -lah



    or,



    cd () command cd "$@" && ls -lah; 


    This would call the cd command built into your shell with the same command line arguments that you gave the function. If the change of directory was successful, the ls would run.



    The command command stops the shell from executing the function recursively.



    The function definition (as written above) would go into your shell's startup file. With bash, this might be ~/.bashrc. The function definition would then be active in the next new interactive shell session. If you want it to be active now, then execute the function definition as-is at the interactive shell prompt, which will define it within your current interactive session.




    1 On systems where cd is available as an external command, this command also does not change directory for the calling process. The only real use for such a command is to provide POSIX compliance and for acting as a test of whether changing directory to a particular one would be possible.






    share|improve this answer















    Your system (like many Unix systems) does not have an external cd command (at least not at that path). Even if it had one, the ls would give you the directory listing of the original directory. An external command can never change directory for the calling process (your shell)1.



    Remove the alias from the environment with unalias cd (and also remove its definition from any shell initialization files that you may have added it to).



    With a shell function, you can get it to work as cd ordinarily does, with an extra invocation of ls at the end if the cd succeeded:



    cd () 
    command cd "$@" && ls -lah



    or,



    cd () command cd "$@" && ls -lah; 


    This would call the cd command built into your shell with the same command line arguments that you gave the function. If the change of directory was successful, the ls would run.



    The command command stops the shell from executing the function recursively.



    The function definition (as written above) would go into your shell's startup file. With bash, this might be ~/.bashrc. The function definition would then be active in the next new interactive shell session. If you want it to be active now, then execute the function definition as-is at the interactive shell prompt, which will define it within your current interactive session.




    1 On systems where cd is available as an external command, this command also does not change directory for the calling process. The only real use for such a command is to provide POSIX compliance and for acting as a test of whether changing directory to a particular one would be possible.







    share|improve this answer















    share|improve this answer



    share|improve this answer








    edited Jun 30 at 8:33


























    answered Jun 25 at 14:34









    Kusalananda

    101k13199312




    101k13199312











    • Where do I have to put the function?
      – Black
      Jun 25 at 14:37






    • 1




      @Black You may put it wherever you would have put the alias definition. In a bash shell, that would probably be in ~/.bashrc.
      – Kusalananda
      Jun 25 at 14:38











    • I added the function to ~/.bashrc but it does not work. ls -lah is not executed at all.
      – Black
      Jun 25 at 14:41










    • @Black No, you add it exactly the way I wrote it. Then it will be active in any new shell session.
      – Kusalananda
      Jun 25 at 14:41







    • 1




      Note that POSIXly, you'd use cd() command cd "$@" && ls -lah; , though that wouldn't work with zsh except in sh emulation. Not all shells have a builtin builtin. In ksh93, it does something different.
      – Stéphane Chazelas
      Jun 25 at 16:30
















    • Where do I have to put the function?
      – Black
      Jun 25 at 14:37






    • 1




      @Black You may put it wherever you would have put the alias definition. In a bash shell, that would probably be in ~/.bashrc.
      – Kusalananda
      Jun 25 at 14:38











    • I added the function to ~/.bashrc but it does not work. ls -lah is not executed at all.
      – Black
      Jun 25 at 14:41










    • @Black No, you add it exactly the way I wrote it. Then it will be active in any new shell session.
      – Kusalananda
      Jun 25 at 14:41







    • 1




      Note that POSIXly, you'd use cd() command cd "$@" && ls -lah; , though that wouldn't work with zsh except in sh emulation. Not all shells have a builtin builtin. In ksh93, it does something different.
      – Stéphane Chazelas
      Jun 25 at 16:30















    Where do I have to put the function?
    – Black
    Jun 25 at 14:37




    Where do I have to put the function?
    – Black
    Jun 25 at 14:37




    1




    1




    @Black You may put it wherever you would have put the alias definition. In a bash shell, that would probably be in ~/.bashrc.
    – Kusalananda
    Jun 25 at 14:38





    @Black You may put it wherever you would have put the alias definition. In a bash shell, that would probably be in ~/.bashrc.
    – Kusalananda
    Jun 25 at 14:38













    I added the function to ~/.bashrc but it does not work. ls -lah is not executed at all.
    – Black
    Jun 25 at 14:41




    I added the function to ~/.bashrc but it does not work. ls -lah is not executed at all.
    – Black
    Jun 25 at 14:41












    @Black No, you add it exactly the way I wrote it. Then it will be active in any new shell session.
    – Kusalananda
    Jun 25 at 14:41





    @Black No, you add it exactly the way I wrote it. Then it will be active in any new shell session.
    – Kusalananda
    Jun 25 at 14:41





    1




    1




    Note that POSIXly, you'd use cd() command cd "$@" && ls -lah; , though that wouldn't work with zsh except in sh emulation. Not all shells have a builtin builtin. In ksh93, it does something different.
    – Stéphane Chazelas
    Jun 25 at 16:30




    Note that POSIXly, you'd use cd() command cd "$@" && ls -lah; , though that wouldn't work with zsh except in sh emulation. Not all shells have a builtin builtin. In ksh93, it does something different.
    – Stéphane Chazelas
    Jun 25 at 16:30












    up vote
    7
    down vote













    I was able to solve it by removing the alias again with unalias cd






    share|improve this answer























    • If you remove the stuck-out text, then this is the only answer that answers the question.
      – ctrl-alt-delor
      Jun 25 at 17:18






    • 1




      @ctrl-alt-delor Note there's no question in the question. We could only guess what the implicit question is. In this situation "why?" is as good as "how to revert?"
      – Kamil Maciorowski
      Jun 26 at 10:26














    up vote
    7
    down vote













    I was able to solve it by removing the alias again with unalias cd






    share|improve this answer























    • If you remove the stuck-out text, then this is the only answer that answers the question.
      – ctrl-alt-delor
      Jun 25 at 17:18






    • 1




      @ctrl-alt-delor Note there's no question in the question. We could only guess what the implicit question is. In this situation "why?" is as good as "how to revert?"
      – Kamil Maciorowski
      Jun 26 at 10:26












    up vote
    7
    down vote










    up vote
    7
    down vote









    I was able to solve it by removing the alias again with unalias cd






    share|improve this answer















    I was able to solve it by removing the alias again with unalias cd







    share|improve this answer















    share|improve this answer



    share|improve this answer








    edited Jun 25 at 17:18









    ctrl-alt-delor

    8,70331947




    8,70331947











    answered Jun 25 at 14:29









    Black

    4932728




    4932728











    • If you remove the stuck-out text, then this is the only answer that answers the question.
      – ctrl-alt-delor
      Jun 25 at 17:18






    • 1




      @ctrl-alt-delor Note there's no question in the question. We could only guess what the implicit question is. In this situation "why?" is as good as "how to revert?"
      – Kamil Maciorowski
      Jun 26 at 10:26
















    • If you remove the stuck-out text, then this is the only answer that answers the question.
      – ctrl-alt-delor
      Jun 25 at 17:18






    • 1




      @ctrl-alt-delor Note there's no question in the question. We could only guess what the implicit question is. In this situation "why?" is as good as "how to revert?"
      – Kamil Maciorowski
      Jun 26 at 10:26















    If you remove the stuck-out text, then this is the only answer that answers the question.
    – ctrl-alt-delor
    Jun 25 at 17:18




    If you remove the stuck-out text, then this is the only answer that answers the question.
    – ctrl-alt-delor
    Jun 25 at 17:18




    1




    1




    @ctrl-alt-delor Note there's no question in the question. We could only guess what the implicit question is. In this situation "why?" is as good as "how to revert?"
    – Kamil Maciorowski
    Jun 26 at 10:26




    @ctrl-alt-delor Note there's no question in the question. We could only guess what the implicit question is. In this situation "why?" is as good as "how to revert?"
    – Kamil Maciorowski
    Jun 26 at 10:26










    up vote
    5
    down vote













    That happened because:



    $ type cd

    cd is a shell builtin





    share|improve this answer

























      up vote
      5
      down vote













      That happened because:



      $ type cd

      cd is a shell builtin





      share|improve this answer























        up vote
        5
        down vote










        up vote
        5
        down vote









        That happened because:



        $ type cd

        cd is a shell builtin





        share|improve this answer













        That happened because:



        $ type cd

        cd is a shell builtin






        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Jun 25 at 14:33









        Vlastimil

        6,2511146115




        6,2511146115






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451778%2fbash-bin-cd-no-such-file-or-directory-automatically-execute-ls-after-cd%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay