Chapter 5
You’ve been running commands like a champ. Now let’s lift the hood and learn what a command actually is, how the shell decides what to run, and how to find great docs fast. By the end, you’ll debug “why isn’t this command running?” in seconds.
🧩 What is a command?
On a typical Linux system, a command can be one of four things:
Executable program A real file on disk (often in
/usr/bin,/bin,/usr/local/bin, etc.). Examples:ls,cp,python3,grep.Shell builtin Implemented inside Bash itself — faster, always available. Examples:
cd,echo,pushd,history.Shell function A tiny script loaded into your shell environment. You can write your own later.
Alias A nickname that expands to another command (e.g.,
ll→ls -alF).
We’ll learn how to identify which one you’re calling and where it lives.
🔎 type — How Bash will interpret a name
type — How Bash will interpret a nameWhat it does: Tells you what kind of command Bash would execute for a given name.
type cd
type ls
type fooTypical outputs:
cd is a shell builtinls is aliased to 'ls --color=auto'cp is /usr/bin/cpbash: type: foo: not found
Pro moves:
Why it matters: If ls is aliased or shadowed by a function, type reveals it instantly.
📍 which — Where is the executable?
which — Where is the executable?What it does: Shows the path of the executable file that would run. Important: which only knows about executables in $PATH. It won’t show builtins, aliases, or functions.
When to use:
You want the file path (
/usr/bin/ls).You’re debugging PATH issues (“why is my custom tool not running?”).
Gotcha: If a name is an alias or function, which won’t tell you — use type for the full picture.
🆘 help — Help for Bash builtins
help — Help for Bash builtinsWhat it does: Built-in docs for builtins only.
You’ll see syntax like:
Square brackets
[]= optionalPipes
|= “one of”...= repeatable
Use help when man shows generic info but you need the Bash-specific behavior.
📚 man — The manual pages
man — The manual pagesWhat it does: Shows the canonical manual page for commands, files, syscalls, etc.
Sections you’ll see a lot:
1User commands5File formats8System admin commands
Navigation (via less):
qquit/wordsearch forwardnnext matchShift+Gendgstarthhelp
Tips:
man -k keyword≈apropos keyword(search titles/descriptions)man -f name≈whatis name(one-line description)
🔍 apropos — “What commands match this idea?”
apropos — “What commands match this idea?”What it does: Searches manpage names and short descriptions.
Use it when you don’t know the exact command but you know the topic. (Under the hood, same DB as man -k.)
🏷️ whatis — One-line summary
whatis — One-line summaryWhat it does: Prints the short description for a man page entry.
Great for a quick sanity check: “is this the command I think it is?”
ℹ️ info — Hyperlinked manuals (GNU style)
info — Hyperlinked manuals (GNU style)What it does: Shows Info documents (often more tutorial-ish than man pages) for GNU tools.
Navigation keys:
Space/Backspacepage forward/backnnext nodepprevious nodeuup (parent)Enterfollow link (the*items)qquit?help
Tip: Many GNU tools (like coreutils) have richer examples in info vs man.
🏷️ alias — Create your own commands
alias — Create your own commandsWhat it does: Defines a shortcut.
View all aliases:
Remove an alias:
Persistence: Put aliases in ~/.bashrc (or ~/.bash_aliases if you source it) so they load in every shell.
Caution: If you alias over a real command name, you can still reach the original with a leading backslash:
🧠 Putting it together — How Bash decides what to run
When you type a name, Bash resolves in this order:
Alias
Function
Builtin
Executable in
$PATH(first match wins)
Use type -a <name> to see the full chain.
🧪 Mini-Lab (5 minutes)
Goal: Diagnose what each name resolves to, then make your own.
🧯 Troubleshooting Playbook
“My command runs the wrong thing.” →
type -a name“It says ‘command not found’.” → Check
$PATH, or typo? Trywhich name“Docs are too terse.” → Try
info, not justman“Builtin vs external behavior differs.” →
help(for builtin specifics)“I want to temporarily bypass an alias.” →
\command args
📝 Exercises
Create two useful aliases in
~/.bashrc, reload withsource ~/.bashrc, and test them.Use
aproposto find a tool that can compare files. Read itsmanpage and try it.Show the file path of
python3and the type ofecho.Use
man 5 passwdand explain, in one sentence, what each field in/etc/passwdmeans.
Date Learned: 17 August 2025
Source: The Linux Command Line, Chapter 5
Last updated