Frequently Asked Question

What is the difference between a builtin, an alias, a function, and an external command?

A builtin is a command implemented inside the shell binary itself, cd, pwd, echo, export, read. Builtins are fast (no fork/exec) and some have to be builtins because they affect the shell's own state: cd couldn't be an external program because changing directory in a child process wouldn't affect the parent.

An alias is a textual shortcut: alias ll='ls -lh' means that whenever you type ll at the start of a command, the shell substitutes ls -lh before executing. Aliases are simple and don't accept arguments in flexible ways. A function is a named block of shell code, myfunc() { ls -lh "$1"; }, which can take arguments, use control flow, and behave like a tiny program. An external command is an executable file on disk found via PATH (/usr/bin/ls, /usr/bin/grep).

Bash resolves commands in this order: alias, function, builtin, then external. Use type ls (or type -a ls to see every match) to find out what a given name actually resolves to. The order matters when you want to override behaviour without losing the original, for instance, alias grep='grep --color=auto' calls the real grep because alias expansion isn't recursive.

Further reading and video