How To

type Command in Linux: Show How the Shell Resolves a Name

The type command in Linux shows how the current shell would interpret a name typed on the command line. It identifies aliases, functions, builtins, keywords, and executable files — giving you the full picture of what will actually run.

type is a shell builtin in Bash, Zsh, and Ksh. Supported options and output format are not identical across shells.

How to Use the type Command in Linux

The syntax is:

bashtype [OPTIONS] NAME...

Check a single command:

bashtype wc        # wc is /usr/bin/wc

Check multiple names at once:

bashtype sleep head

type vs which. which searches only PATH for executable files. type understands the full shell resolution order: aliases first, then functions, builtins, keywords, and finally PATH executables. This matters in practice: if grep is aliased to grep --color=auto, then type grep returns alias — because that is what the shell will actually run, not the binary.

Command Types: Alias, Function, Builtin, File, and Keyword

Use -t to print a single descriptive word:

bashtype -t grep     # aliastype -t rvm      # functiontype -t echo     # builtintype -t cut      # filetype -t for      # keyword

In Zsh, the word command may appear where Bash reports file. The exact wording depends on the shell.

Builtins are handled directly by the shell without forking a new process. echocdpwd, and type itself are all builtins. This is why cd cannot be replaced by an external script — it must run inside the current shell process to actually change the working directory.

All Locations with -a, Path Options, and Scripting Use

-a shows every location where a name is found, including aliases, functions, and disk executables:

bashtype -a pwd
pwd is a shell builtinpwd is /bin/pwd

This reveals that pwd exists as both a builtin and a standalone executable on PATH. Useful when an alias or function is shadowing an executable you did not expect.

-p prints the path only if the resolved name is a disk file. It produces no output for builtins, aliases, or functions:

bashtype -p pwd    # no output — pwd resolves as a builtin first

-P (Bash only) forces a PATH search even when a builtin or function with the same name exists:

bashtype -P pwd    # /bin/pwd

Checking command existence in scripts. Use type with exit code checking to test whether a command is available:

bashtype command > /dev/null 2>&1 && echo "found" || echo "not found"

For the most portable approach across shells, command -v name is the POSIX standard alternative and works reliably in Bash, Zsh, Dash, and sh.

Use type name to see exactly how your shell will resolve a command before running it. Use -a to reveal aliases or functions that shadow executables, -P to force a PATH search, and command -v for portable existence checks in scripts. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

How to Check Memory Usage in Linux: free, top, and /proc/meminfo

When a Linux system is slow or behaving unexpectedly, memory is one of the first…

53 minutes ago

ip Command in Linux: Configure Interfaces, Routes, and ARP

The ip command is the standard network configuration tool on modern Linux systems. It is part of…

58 minutes ago

chown Command in Linux: Change File and Directory Ownership

Every file and directory in Linux has an owner (a user) and a group. Together…

1 hour ago

How to Remove Files and Directories in Linux: rm, shred, rmdir

The command line does not have a Trash folder. When you delete a file from…

1 day ago

How to Create a systemd Service File in Linux: Step-by-Step Guide

Systemd is the init system on most modern Linux distributions. A service file (also called…

1 day ago

How to Create Users in Linux with useradd: A Complete Guide

Linux is a multi-user system. Each person or service that needs access should have its…

1 day ago