-bash: /bin/cd: No such file or directory - automatically execute ls after cd
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.
I was able to solve it by removing the alias again with unalias cd
That happened because:
$ type cd
cd is a shell builtin