Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

type

Show what a command name really is: an alias, a shell keyword, a function, a built-in or a program file.

Niveau
RHCSA-examen
Groep
Shell en hulp
Root nodig
Nee
Pakket
bash (built-in)

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

type is built into Bash. It answers the question "if I type this name, what will run?" It knows about aliases, functions and shell built-ins, which a tool like which cannot see.

Use it when a command does something you did not expect: maybe an alias with the same name hides the real program, or a script found a different program in $PATH.

The help text is in Bash itself: help type.

Zo schrijf je het

type [-afptP] NAME [NAME ...]

Opties 5

Meest gebruikt

-t
Print only one word: alias, keyword, function, builtin, file, or nothing if not found.
-a
Show every place where NAME is found: alias, function, built-in and every file in $PATH.
-p
Print the path of the file that would run, but only when NAME is a file (nothing for an alias or built-in).
-P
Search $PATH for a file, even when NAME is also an alias, function or built-in.
-f
Do not look for shell functions.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Find out what a name is

    type ls
    ls is aliased to `ls --color=auto'

    On RHEL, ls is an alias that adds colors.

  2. 2Show every match, in the order Bash uses them

    type -a ls
    ls is aliased to `ls --color=auto'
    ls is /usr/bin/ls

    The first line wins. The program file is only used when there is no alias.

  3. 3Get one word for a script

    type -t cd
    builtin

    Possible answers: alias, keyword, function, builtin, file.

  4. 4Check if a command is installed before you use it

    if type -P jq >/dev/null; then echo "jq found"; else echo "please install jq"; fi

    type -P returns an error code when the program is not in $PATH. Good for install checks.

  5. 5See if a name is a shell keyword

    type if
    if is a shell keyword

    Keywords like if, for and [[ are part of the Bash language.

  6. 6Find the real program behind an alias

    type -P grep
    /usr/bin/grep

    Shows the file even though grep is also an alias.

  7. 7Look at a shell function

    type my_backup

    If my_backup is a function, Bash prints its full code. Useful to debug functions from ~/.bashrc.

  8. 8Check several names at once

    type -t python3 docker podman kubectl
    file
    file

    Names that are not found print nothing in -t mode. Here only two of four are installed.

  9. 9Find out why an old version of a tool runs

    type -a terraform
    terraform is /usr/local/bin/terraform
    terraform is /usr/bin/terraform

    Two copies are installed. The first one in $PATH wins; remove or rename the old one.

  10. 10Detect a hidden alias in a security review

    type sudo

    If an attacker added alias sudo=... to a .bashrc, type shows it. Real sudo is /usr/bin/sudo.

  11. 11Use type in a script to require a tool

    type -P rsync >/dev/null || { echo "rsync is missing" >&2; exit 1; }

    Stops the script early with a clear message.

Let op

  • type is a Bash built-in. It does not exist as a program file, so sudo type does not work.
  • which does not know functions and built-ins (it only searches files), so the two can give different answers.

Tips om te onthouden

  • type = what runs, type -a = everything that could run, type -P = only the file.
  • Remember the order Bash uses: alias → keyword → function → built-in → file in $PATH.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man type