The command which cd
prints nothing. Same for whatis cd
and whereis cd
. How can I find out if cd is an alias, function, or bash built-in? I'm using Ubuntu 12.04.
3 Answers
In bash, which
is an external utility. It only finds external commands: it does not know about aliases, builtins or functions. The same goes for whatis
and whereis
.
Forget which
and use type
instead.
$ type cd
cd is a shell builtin
Builtins don't have a man page of their own (unless they also exist as an external utility, but then you get the documentation of the external utility, which may support different options). They are documented in the bash manual.
See also How to use which
on an aliased command? and My which
command may be wrong (sometimes)?
-
I like
type -a
too -- it shows all executables/alias/function -- exampletype -a [
Jan 9, 2013 at 23:50 -
type
with its various options is definitely more reliable.which
shows tremendous variations in power from distro to distro (cf. red hat vs debian).– reasgtJan 10, 2013 at 21:55
man bash
will tell you that. Move to the end and then search for BASH BUILTIN COMMANDS. You can read on from there.
To list all bash aliases:
alias
To list all defined function names:
typeset -F
To see the list of bash builtins, check the bash manpage.
You can probably hack together a single script to grep through the output of each command above.