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:
type -a ls # show ALL resolutions (alias, builtin, function, PATH hits)
type -t ls # show only the type: alias/builtin/file/functionWhy 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.
which ls
which cp
which cd # likely “no cd in …” (because `cd` is a builtin)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.
help cd
help history
help -m cd # alternate (manpage-like) formattingYou’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.
man ls # program reference
man 5 passwd # section 5 (file formats) for /etc/passwdSections 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.
apropos partition
apropos network timeUse 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.
whatis ls
whatis passwdGreat 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.
info coreutils 'ls invocation' # jump straight to ls section
info ls # open the ls entry (if present)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.
alias ll='ls -alF'
alias gs='git status'
alias ...='cd ../..'View all aliases:
aliasRemove an alias:
unalias llPersistence: 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:
alias ls='ls --color=auto'
\ls # runs the real ls, bypassing the alias🧠 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.
# 1) What are these?
type cd
type ls
type echo
type grep
which grep
# 2) Add and test aliases
alias ll='ls -alF'
alias ls='ls --color=auto'
type ls
\ls -l # bypass alias
# 3) Check docs three ways
help cd
man ls
whatis ls
apropos directory
info coreutils 'ls invocation'🧯 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