هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
ماذا يفعل
which searches the folders in your $PATH, from left to right, and prints the first file with that name. It answers "where is this program on the disk?".
On RHEL, which for Bash users is an alias that also shows aliases and functions (alias which='(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot').
To know which package a program comes from, use rpm -qf $(which NAME).
طريقة الكتابة
which [OPTIONS] PROGRAM [PROGRAM ...]الخيارات 12
الأكثر استخدامًا
لا يوجد شيء يطابق هذا الفلتر.
أمثلة 11
$ مستخدم عادي# بصلاحية root (أو مع sudo)
1Find where a program is
which passwd /usr/bin/passwdThe program file that runs when you type
passwd.2See all copies of a program in $PATH
which -a python3 /usr/bin/python3 /usr/local/bin/python3The first one wins. Two copies often explain "wrong version" problems.
3Find the package of a program
rpm -qf $(which ss) iproute-6.x.x.el10.x86_64Now you know which package to update or reinstall.
4Check if a tool exists in a script
which ansible >/dev/null 2>&1 && echo "ansible installed"The exit code is 0 when found, 1 when not found.
5Show the alias too (RHEL default)
which ll alias ll='ls -l --color=auto' /usr/bin/lsBecause of the RHEL alias,
whichalso shows aliases in an interactive shell.6Use the plain program without the alias
/usr/bin/which --skip-alias llIn a script the alias does not exist; this shows what a script would find.
7Check the path of a privileged program in a review
which -a sudoOnly
/usr/bin/sudoshould appear. Anothersudoearlier in $PATH is a red flag.8Find which shell a user would get
which bash zsh fish /usr/bin/bashOnly installed shells are printed; the others give an error message.
9Get the path for a cron job or a systemd unit
which podman /usr/bin/podmancron and systemd use a short $PATH. Write the full path in
ExecStart=and crontab lines.10Check many tools at once before a deployment
for t in git curl jq rsync; do which $t >/dev/null || echo "missing: $t"; donePrints only the tools that are not installed.
11Compare with type
which cd; type cdwhichfinds no file forcd(it is a built-in);typeexplains what it is.
لا يوجد شيء يطابق هذا الفلتر.
انتبه
whichonly searches files in $PATH. It does not know built-ins likecd(usetype).sudo which NAMEcan give another answer, because root has a different $PATH.