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