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

What I Wish I Knew Before Learning Malware Analysis and Reverse Engineering

When I first started learning malware analysis and reverse engineering, I thought the hardest part…

1 day ago

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

2 weeks ago

git cherry-pick Command: Apply Commits from Another Branch

Sometimes the change you need already exists, just on the wrong branch. A hotfix lands…

2 weeks ago

Best Email APIs for Secure Business Email: Why Developers Are Moving Beyond SMTP

Email is still one of the most important communication channels inside modern applications. Password resets,…

2 weeks ago

Nginx Commands in Linux: Start, Stop, Reload, Test, and Log

Nginx is a high-performance web server and reverse proxy trusted by some of the largest…

2 weeks ago

ufw Command in Linux: Manage Firewall Rules with Examples

ufw (Uncomplicated Firewall) sits on top of iptables (or nftables on newer systems) and replaces…

2 weeks ago