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.
/bin/cd
;cd
is a shell built-in. – Andy Dalton Jun 25 '18 at 14:32/bin/cd
, but that only exists for formal reasons and is not usable for anything. – schily Jun 25 '18 at 14:41/bin/cd
must be the most useless command. – ctrl-alt-delor Jun 25 '18 at 17:15type cd
– PersianGulf Jun 25 '18 at 17:26-a
. One example: MacOStype -a cd
outputs "cd is a shell builtin" and "cd is /usr/bin/cd". See this – Dennis Williamson Jun 25 '18 at 21:21-a
on Debian andbash
shell. – PersianGulf Jun 26 '18 at 11:35-a
(even on Debian and Bash), it will tell you all the ways the argument is defined (aliases, builtins, and functions and executable files - including instances in multiple parts of thePATH
). – Dennis Williamson Jun 26 '18 at 15:33