How to Use the type Command to Identify Aliases and Shell Builtins in Linux

When you type a simple command like ls into a Linux terminal, the operating system executes it flawlessly. However, Linux is a complex environment where multiple tools can share the exact same name. For example, ls might be the standard binary executable located in /usr/bin/ls, or it might be a custom shell alias you created in your .bashrc file, or it could even be a built-in function of the Bash shell itself. If a command starts behaving strangely and you need to figure out exactly what the system is executing behind the scenes, you use the type command.

Basic Usage: Identifying the Command Type

To find out what a specific command actually is, you type type followed by the command name.

type ls

If you run this on a standard Ubuntu system, the output will likely be: ls is aliased to `ls --color=auto'. This immediately tells you that when you type ls, the system isn’t just running the raw binary; it is triggering a shell alias that forces the output to be colorized.

If you run the command on something fundamental to the shell, like cd (change directory):

type cd

The output will definitively state: cd is a shell builtin. This means there is no standalone file named “cd” on your hard drive; the command is hardcoded directly into the memory of the Bash shell itself.

Finding the Exact Binary Path

If you are trying to execute a script or write an automation routine, you often need to know the exact, absolute file path to a binary executable (like Python or standard grep). By adding the -p (path) flag, you force type to return nothing but the absolute file location.

type -p grep

This will typically return a clean, highly usable path like /usr/bin/grep or /bin/grep. If the command is an alias or a shell builtin (which do not have physical file paths), the -p flag will silently return nothing at all.

Revealing All Possible Matches

Because of how the Linux $PATH variable works, you might actually have three different versions of Python installed on your system in three different directories (e.g., one in /usr/bin, one in /usr/local/bin, and one in /opt). The system executes the first one it finds. To see all the locations where a command name exists across your entire system path, use the -a (all) flag.

type -a python3

This will print a comprehensive list of every matching executable or alias found, ordered exactly by how the system prioritizes them. The top result is what actually executes when you type the command, while the others remain dormant on your hard drive.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.