Learn › Linux Foundations › Bash Shell Environment
type - a hands-on Linux lab on a real virtual machine.
Ask the shell what actually runs with type. It classifies a name as an alias, keyword, function, builtin, or file, and reports the winner in the order the shell checks. Bare type names the winner, -a lists every match, -t prints just the category. The alias beats the file, which is why type sees what the external which never can.
You type ls and the machine lists your files. You type cd and it moves you. Simple. But a single name can point at more than one thing at once. There can be a program called ls sitting on disk AND a shortcut called ls living in your shell, both answering to the same word.
So when two things share a name, which one actually runs? Guessing is how a command behaves in a way you did not expect and you have no idea why. There is one command whose entire job is to answer that question, out loud, before anything runs. It is called type.
The black boxes in this lesson are a practice terminal: a safe sandbox that only checks the one command each step teaches, so you cannot break anything. Nothing here changes your machine. type only reports; it never runs the thing it looks up.
type takes a name and tells you what kind of thing that name is. When you press Enter on a word, the shell does not just search the disk. It checks several places in a fixed order, and the first match wins. type walks that same order and reports the winner.
There are five kinds of thing a name can be. An alias is a shortcut you or the system defined, like ls standing in for ls --color=auto. A keyword is a word built into the shell's grammar, like if. A function is a small block of shell code saved under a name. A builtin is a command baked into the shell itself, like cd. And a file is a real program sitting on disk, like /usr/bin/ls. type names which of the five you are dealing with.
Start with the plainest case. Ask type about cd, the command that changes your directory:
type cd
prompt: student@linuxcamp:~$ answer: type cd output: cd is a shell builtin hint: Type the word type, a space, then cd: type cd
There it is: cd is a shell builtin. cd is not a program on the disk. It is baked directly into the shell, because changing the shell's own current directory is something only the shell itself can do. That is why you will never find a file called cd to run. type told you its true nature in four words.
type is happy to describe anything, including itself. It is also a shell builtin, so asking about it is a quick way to prove the tool is what it claims to be. Run it on its own name:
type type
prompt: student@linuxcamp:~$ answer: type type output: type is a shell builtin hint: The word type twice, separated by a space: type type
Now try a word that is not a command at all, but part of the shell's grammar. if is how you start a decision in a script. It is not a program and not a builtin; it is a keyword, a reserved word the shell reads specially. Ask about it:
type if
prompt: student@linuxcamp:~$ answer: type if output: if is a shell keyword hint: The word type, a space, then if: type if
Two different verdicts from the same tool. type is a builtin, and if is a keyword. You did not have to know in advance; you asked, and the shell told you the category. This is the habit to build: when a name behaves oddly, ask type what it really is before you guess.
Here is the case that catches people. On most machines you sit down at, ls is not the program on disk. Someone, usually your system's default setup, defined an alias: a shortcut that quietly rewrites ls into ls --color=auto so your listings come out coloured. That alias is checked BEFORE any file on disk. It wins.
Ask type about ls and watch it name the alias, not the program:
type ls
prompt: student@linuxcamp:~$ answer: type ls output: ls is aliased to `ls --color=auto' hint: The word type, a space, then ls: type ls
That exact line is what most login shells show, but this is the one output in the lesson that depends on your machine. If your shell has the color alias set, you get ls is aliased to as above. If it does NOT, type ls skips straight to the file and prints ls is /usr/bin/ls instead. Both are correct answers to the same question. Which one you see tells you whether an alias is in the way, and that is exactly the thing type exists to reveal.
This is the whole point of type. The word ls matched an alias before it ever reached the disk, so the alias is what runs. There genuinely is a program at /usr/bin/ls, but the alias sits in front of it and wins. Order matters: alias, then keyword, then function, then builtin, then file on the PATH. type reports whichever comes first, so it tells you which one actually runs when you press Enter.
Bare type shows you the winner. But sometimes you want the full story: is there a file hiding behind that alias, and where is it? The -a flag, for all, prints every match for the name, in the same priority order, one per line.
Ask for everything ls resolves to:
type -a ls
prompt: student@linuxcamp:~$ answer: type -a ls output: ls is aliased to `ls --color=auto' ls is /usr/bin/ls hint: Add the -a flag between type and ls: type -a ls
The first line is the same alias as before, still the winner. The second line is the file on disk that the alias sits in front of. If your machine has no ls alias, you will see only the /usr/bin/ls line, since there is just one match to show. The order is always winner first. -a is how you confirm a real program exists underneath a shortcut, and exactly where it lives.
Sometimes you do not want a sentence, you want a single word you can act on: is this an alias, a keyword, a function, a builtin, or a file? The -t flag, for type, prints only that one category word and nothing else.
Ask for the bare category of cd:
type -t cd
prompt: student@linuxcamp:~$ answer: type -t cd output: builtin hint: Add the -t flag between type and cd: type -t cd
One word: builtin. No sentence, no path, just the category. -t always prints exactly one of five words: alias, keyword, function, builtin, or file. It is the quiet form, the one you reach for when you already know you want the answer boiled down to a single label.
type is only useful if it is honest when the answer is nothing. Ask it about a name that is not an alias, keyword, function, builtin, or any file on your PATH, and it says so plainly and stops.
Make up a name that does not exist and ask about it:
type nosuchcmd
prompt: student@linuxcamp:~$ answer: type nosuchcmd output: bash: type: nosuchcmd: not found hint: The word type, a space, then the made-up name nosuchcmd: type nosuchcmd
The literal message is bash: type: nosuchcmd: not found. It means exactly what it says: the shell checked all five places and no nosuchcmd turned up anywhere. type also exits with a failure code (1) here, which scripts can check. First thing to look at when you see this: a typo in the name, or a program you thought was installed but is not. Compare it to a name that DOES resolve, and the difference is your answer.
You will meet another command that looks like it does the same job: which. It does not, and the gap matters. which is an external program that only searches files on your PATH. It never knows about aliases, keywords, functions, or builtins, because those live inside the shell and an outside program cannot see them.
So which cd often finds nothing, because cd is a builtin with no file. And which ls reports only the file /usr/bin/ls, silently missing the alias that actually runs. type is a shell builtin, so it sees everything the shell sees. When you want the true answer to which one runs, type is the command that knows them all. There is a full lesson on which coming next.
One sentence to keep: which looks only on disk, type looks everywhere the shell looks. If a command is behaving strangely and which shrugs, ask type; the answer is usually an alias or a builtin which could never see.
Scaffolding off. No command is printed this time. You have every piece you need.
You suspect ls is running through an alias, but you also want to know whether a real program is hiding behind it and where it lives. You want the complete picture: every way the name ls resolves, in order, winner first, all on the screen at once.
prompt: student@linuxcamp:~$ answer: type -a ls output: ls is aliased to `ls --color=auto' ls is /usr/bin/ls hint: You want ALL matches, not just the winner. Combine type with the flag that means all, then the name: type, then -a, then ls.
That is the move. The -a flag asked for every match, and the name ls gave you both: the alias that wins on top, and the real file underneath it. If your machine has no alias, you would see just the one file line, which is still the complete and correct answer. You recalled the flag from memory and combined it with a name, which is exactly what the real machine will ask of you.
You earned this cheat sheet. Every row is a form of type you just ran:
And the five categories type reports, in the order the shell checks them: alias, keyword, function, builtin, file. When a command surprises you, type <name> is the first thing to type, and the category it prints is the first clue to read.
There is also type -p ls, which prints only the disk path if the name is a file, and prints nothing if it is an alias or builtin. It is the narrow cousin of -a: use -a to see everything, -p when you want only the file's location.
The practice terminal has shown you the shape of type. You have the plain form that names the winner, -a to see every match, -t for just the category word, the alias-beats-file aha, the not-found error, and how type sees what which never can. Every one of those you typed yourself.
The Bash Shell Environment module ends with one real Linux machine, the bash-environment capstone mission, and that is where you run type for real. A VM boots just for you, with its own aliases, builtins, and PATH. It hands you objectives that use exactly what you practiced across this module: variables, aliases, the environment, and looking up what really runs. One difference from here: the mission shows no commands. You read the objective, you recall the command, you type it. That recall is what makes it stick.
Finish the other Bash Shell Environment lessons, then go ask a real shell what really runs.
Practice type in a real Linux terminal at The Linux Camp. Progress is verified automatically as you type commands on the machine.