🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

type Command

Beginner Shell Scripting man(1)

Show how a command name is interpreted by the shell

👁 10 views 📅 Updated: Mar 15, 2026
SYNTAX
type [OPTION]... NAME

What Does type Do?

type identifies how a command name would be interpreted by the shell. It reveals whether a name is a shell built-in, an alias, a function, an external executable, or a keyword.

type is more comprehensive than which — it knows about shell built-ins (cd, echo), aliases, and functions, while which only finds executables in PATH. This makes type the definitive tool for understanding what happens when you type a command.

type is a shell built-in itself, available in bash and most other shells.

Options & Flags

OptionDescriptionExample
-t Show type only (alias, function, builtin, file, keyword) type -t ls
-a Show all matches (all aliases, functions, and executables) type -a echo
-p Show executable path (skip aliases/functions) type -p python3
-f Do not look up functions type -f cd

Practical Examples

#1 Identify a command

Shows what 'ls' resolves to.
$ type ls
Output: ls is aliased to 'ls --color=auto'

#2 Show command type only

Returns just the type category.
$ type -t cd
Output: builtin

#3 Show all definitions

Shows all versions of echo — built-in and external.
$ type -a echo
Output: echo is a shell builtin echo is /usr/bin/echo

#4 Check if command exists

Checks if a command is available (any type).
$ type -t docker > /dev/null 2>&1 && echo "Found" || echo "Not found"

#5 Find executable path

Shows only the file path, ignoring aliases and functions.
$ type -p python3
Output: /usr/bin/python3

#6 Identify built-ins

Checks whether common commands are built-ins or externals.
$ for cmd in cd echo test printf; do echo "$cmd: $(type -t $cmd)"; done
Output: cd: builtin echo: builtin test: builtin printf: builtin

Tips & Best Practices

type vs which: type knows about aliases, functions, and built-ins. which only finds executables in PATH. type gives you the complete picture.
Debug command resolution: Use type -a command to see everything: aliases, functions, built-ins, AND executables. The first match is what runs.
Shell-specific: type is a shell built-in and its output varies between bash, zsh, and other shells. The -t flag is the most portable.

Frequently Asked Questions

What is the difference between type and which?
type shows aliases, functions, built-ins, and executables. which only shows executables in PATH. type gives the complete picture of how a command resolves.
How do I check if a command is a built-in?
Use type -t command. It returns 'builtin' for shell built-ins, 'file' for external executables, 'alias' for aliases, 'function' for functions.
How do I find all definitions of a command?
Use type -a command. It shows every alias, function, built-in, and executable that matches, in the order they would be resolved.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →