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
Niets past bij dit filter.
Voorbeelden 11
$ als gewone gebruiker# als root (of met sudo)
1Find out what a name is
type ls ls is aliased to `ls --color=auto'On RHEL,
lsis an alias that adds colors.2Show every match, in the order Bash uses them
type -a ls ls is aliased to `ls --color=auto' ls is /usr/bin/lsThe first line wins. The program file is only used when there is no alias.
3Get one word for a script
type -t cd builtinPossible answers: alias, keyword, function, builtin, file.
4Check if a command is installed before you use it
type -Preturns an error code when the program is not in $PATH. Good for install checks.5See if a name is a shell keyword
type if if is a shell keywordKeywords like
if,forand[[are part of the Bash language.6Find the real program behind an alias
type -P grep /usr/bin/grepShows the file even though
grepis also an alias.7Look at a shell function
type my_backupIf
my_backupis a function, Bash prints its full code. Useful to debug functions from~/.bashrc.8Check several names at once
type -t python3 docker podman kubectl file fileNames that are not found print nothing in -t mode. Here only two of four are installed.
9Find out why an old version of a tool runs
type -a terraform terraform is /usr/local/bin/terraform terraform is /usr/bin/terraformTwo copies are installed. The first one in $PATH wins; remove or rename the old one.
10Detect a hidden alias in a security review
type sudoIf an attacker added
alias sudo=...to a.bashrc,typeshows it. Real sudo is/usr/bin/sudo.11Use type in a script to require a tool
Stops the script early with a clear message.
Niets past bij dit filter.
Let op
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.