Skip to content

The shell `type` command

This week I stumbled on a post about a command that has existed in the bash shell (and other shells like my preferred zsh) for years (originally introduced in the 80s) but that I’d never seen before.

The type command will indicate how a command would be executed.

For example:

type echo

would return

echo is a shell builtin

telling me that echo is a built-in function of this shell, as opposed to an executable binary in the file system.

Whereas doing:

type git

returns:

git is /opt/homebrew/bin/git

showing me at the git command is an executable, and the path that executable is found in.

This works for:

  • Built in shell commands
  • Executables
  • Aliases
  • Reserved Keywords

You can also get the results for multiple commands back at once. If you run type followed by a list of commands separated by spaces, it will return one line for each command specified.

For example:

type -P echo cat sail if

returns:

echo is a shell builtin
echo is /bin/echo
cat is /bin/cat
sail is an alias for [ -f sail ] && bash sail || bash vendor/bin/sail

3 Comments

  1. @shooper Incredible!

    Wish I'd known about this while I was migrating from MAMP to Valet… So much time spent trying to figure out what was being loaded by “php”, "mysql” etc. And I have so many aliases banging around that sometimes I don't even realized I've overwritten a build-in command 😅

    I should tattoo this on the back of my hand 🤔

    • Shawn Hooper Shawn Hooper

      Next to a tattoo of the tar command’s parameters!

      • @shooper HAHA omg just yesterday I did some happy go lucky `gunzip xyz.gz` forgetting that that would remove the file 💀 💀 💀

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.