which

which toont het volledige pad van het uitvoerbare bestand dat de shell zou uitvoeren.

Basisgebruik

which python3
# /usr/bin/python3

which nginx
# /usr/sbin/nginx

Opties

OptieBetekenis
-aToon alle overeenkomsten in $PATH

Voorbeelden

Welke Python wordt gebruikt:

which python python3 python3.11

Alle exemplaren:

which -a python3
# /usr/bin/python3
# /usr/local/bin/python3

Controleren of commando beschikbaar is:

if ! which rsync &>/dev/null; then
    echo "rsync niet gevonden"
    exit 1
fi

Beperking

which vindt alleen externe programma's in $PATH. Het vindt geen shell-aliassen, ingebouwde commando's of functies. Gebruik type daarvoor:

type ls       # ls is aliased to 'ls --color=auto'
type cd       # cd is a shell builtin

Tip

Als een commando anders gedraagt dan verwacht, controleer met which commando of je wel het juiste binaire bestand gebruikt.

shell