That's a very practical question! Since shell builtins are integral to the shell and don't usually have separate executable files in your $PATH, identifying them isn't quite as straightforward as looking for a file. However, Labby can share a few reliable methods.
Here are the primary ways to identify shell builtins:
-
Using the
typeCommand (Most Common and Recommended)
This is the most direct and generally preferred method. As you're learning in this step,typetells you exactly how the shell will interpret a command name.If a command is a builtin,
typewill clearly state it.Example:
type cd # Output: cd is a shell builtin type echo # Output: echo is a shell builtin type export # Output: export is a shell builtinIf it's not a builtin,
typewill tell you its actual type (alias, function, or external executable):type ls # Output: ls is aliased to `ls --color=auto' (or ls is /usr/bin/ls if no alias) type python # Output: python is /usr/bin/python -
Using
help(for Bash/Zsh specific builtins)
Many shells (like Bash and Zsh) have ahelpcommand that provides documentation specifically for their builtins. Ifhelpcan find documentation for a command, it's almost certainly a builtin.Example:
help cd # Output: cd: cd [-L|[-P [-e]] [-@]] [dir] # Change the current directory to DIR. ... (and a lot more) help alias # Output: alias: alias [-p] [name[=value] ...] # Define or display aliases. ...If you try
helpon an external command, it will usually give an error or complain:help ls # Output: bash: help: no help topics match `ls'. Try `help help' or `info bash'. -
Checking Shell Documentation
The most definitive way is to consult the official documentation for your specific shell (e.g., Bash Reference Manual, Zsh Manual). These manuals will have a dedicated section listing all of the shell's built-in commands. This is useful if you want a comprehensive list rather than checking commands one by one.For Bash, you can often find a list by searching for "Bash Builtins".
For Zsh, similar search terms will lead you to thezshbuiltinsman page. -
compgen -b(for Bash specific builtins)
This is a more advanced shell feature, primarily used for programmable tab completion, but-bspecifically lists builtins.compgen -b # Output: # . # : # [ # alias # bg # bind # break # builtin # ... (many more)This will give you a long list of builtins.
In summary, the type command is your best friend for quickly identifying what any given command name refers to, including whether it's a shell builtin. For a more general overview, help and shell documentation are excellent resources.