Finding your way on an unfamiliar machine
Before any objective, there is the skill of working out what a machine will actually do. This guide covers the three things that decide it: whether a command is a builtin or a program, where the shell looks and in what order, and how to find documentation from the command line - including the manual sections that explain why man passwd and man 5 passwd are different pages.
Start Here Guide 3 of 33 Beginner
- OSUbuntu 26.04 LTS
- Kernel7.0.0-30-generic
- systemd259
- TimeAbout 15 min
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| LPIC1-A01 | 192.168.0.76 | Ubuntu 26.04 LTS | Debian-family host - dpkg and apt, which objective 102.4 names | 2 Core | 4 GB | 50 GB |
This guide includes
Use this before any objective. This matters because which and the shell can disagree - a command is not always a program, and the answer depends on which of them you asked.
- finding that a command is not always a program, with
type -a - seeing where
whichdisagrees with the shell - reading
$PATHas a list, in the order that decides the winner - finding a manual page you did not know existed, in another section
Before you start
- what-lpic-1-asks
-
A command is not always a program
type -ashows every candidate, in the order the shell considers them.bash Example session type -a echo; echo "---"; type -a lsecho is a shell builtinecho is /usr/bin/echoecho is /bin/echo---ls is /usr/bin/lsls is /bin/lstype -a cd; echo "--- cd MUST be a builtin: a child process could not change your directory"cd is a shell builtin--- cd MUST be a builtin: a child process could not change your directoryExpected result
echois a shell builtin AND/usr/bin/echoAND/bin/echo;lsis only a program;cdis only a builtin.Success conditionYou can tell what will actually run before you run it.
-
Where `which` disagrees with the shell
Two tools that look interchangeable and are not.
bash Example session which echo; command -v echo; echo "--- which finds the binary, command -v finds what will actually run"echo: shell built-in commandecho--- which finds the binary, command -v finds what will actually runExpected result
whichreportsecho: shell built-in command;command -vreportsecho.Success conditionYou know which tool to trust in a script.
-
Where the shell looks, and in what order
$PATHis a list, and the order is the whole story.bash Example session echo $PATH | tr ':' '\n'/usr/local/sbin/usr/local/bin/usr/sbin/usr/bin/sbin/bin/usr/games/usr/local/games/snap/binecho $PATH | tr ':' '\n' | head -1; echo "--- the FIRST match wins, which is how a local bin shadows a system one"/usr/local/sbin--- the FIRST match wins, which is how a local bin shadows a system oneExpected resultNine directories,
/usr/local/sbinfirst and/snap/binlast.Success conditionYou can explain why a command ran the version you did not expect.
-
Reading a manual page you did not know existed
The same word can be several different pages.
bash Example session man -f passwd 2>/dev/null | head -4; echo "--- the same word in several manual sections"passwd (1) - change user passwordpasswd (1ssl) - OpenSSL application commandspasswd (5) - the password file--- the same word in several manual sectionsapropos -s 1 'list directory' 2>/dev/null | head -3; echo "--- search by description when you do not know the name"dir (1) - List directory contents. Ignore files and directories ...gnudir (1) - list directory contentsgnuls (1) - list directory contents--- search by description when you do not know the nameman 5 passwd | head -6; echo "--- section 5 is the FILE, section 1 is the command"PASSWD(5) File Formats and Configuration PASSWD(5) NAME passwd - the password file DESCRIPTION--- section 5 is the FILE, section 1 is the commandExpected result
passwd (1)the command,passwd (5)the file, andpasswd (1ssl)from OpenSSL - then a description search, then section 5 itself.Success conditionYou can find documentation on a machine with no browser.
Troubleshooting
whichnames a binary but the shell runs something else.Why:
whichis an external program that searches PATH only. It cannot see shell builtins, functions or aliases, and the shell prefers all three.Fix:Use
type -a <name>, which lists every candidate in the order the shell considers them -echois a builtin AND /usr/bin/echo AND /bin/echo on this machine.A command is installed and still reports command not found.
Why: Its directory is not in PATH for this shell - commonly
/usr/sbinfor a non-root user, or a directory added only by a login profile.Fix:
echo $PATHand compare with the file's location fromcommand -vin a root shell. Order matters: the nine directories here are searched left to right, /usr/local/sbin first.man <name>shows the wrong page, or one you did not expect.Why: The same name exists in several sections -
passwd(1)is the command,passwd(5)is the file format, andpasswd(1ssl)comes from OpenSSL.Fix:
man -f <name>orwhatis <name>lists every section. Ask for one directly withman 5 passwd, and search all of them withman -k <keyword>.