In Chapter 1, a command was "the name of a program". In "The Linux Directory Layout", you saw that programs are in /usr/bin. Now look closer: a program is a file that the computer can run.
which: where is the program?
which writes the path of the program file for a command:
text
learner@tidepool:~$ which whoami
/usr/bin/whoami
learner@tidepool:~$ ls -l /usr/bin/whoami
-rwxr-xr-x 1 root root 35344 Apr 5 2024 /usr/bin/whoamiwhoamiyou type
Shellfinds the file
/usr/bin/whoamithe program
The chapter "Variables and the Environment" explains how the shell finds the file.
A program file is not a text file
A program file holds instructions for the computer, not text for people. cat on a program shows characters that you cannot read. Do not do it: it can make the terminal show strange characters.
Not every command is a file
cd is part of the shell. It has no program file, so which writes nothing:
text
learner@tidepool:~$ which cd
learner@tidepool:~$| Command | Where it is |
|---|---|
whoami, ls, grep | A program file in /usr/bin |
cd | Inside the shell |