• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

which: command not found

by admin

The which command displays the complete path of a specified command by searching the directories assigned to the PATH variable. For example, upon entering which cat, the following output is displayed: /bin/cat.

$ which cat
/bin/cat

The which command can therefore help you locate where a program has been installed in case you need to modify this. It can also help you identify which version of a command you’re using if there are multiple binaries of the command stored in different locations, one of which may be more ideal. By identifying where a command is running from, you can troubleshoot unexpected behavior from that command.

Syntax

The syntax of the which command is:

$ which [options] {program names}

If you encounter below error while running the which command:

which: command not found

you may try installing the below package as per your choice of distribution:

Distribution Command
OS X brew install debianutils
Debian apt-get install debianutils
Ubuntu apt-get install npm
Alpine apk add which
Arch Linux pacman -S which
Kali Linux apt-get install debianutils
CentOS yum install which
Fedora dnf install which
Raspbian apt-get install debianutils

which Command Examples

1. Search the PATH environment variable and display the location of any matching executables:

$ which executable

2. If there are multiple executables which match, display all:

$ which -a executable

Final Thoughts

The which command locates an executable file in your shell’s search path. You can even find the which program itself:

$ which which
/usr/bin/which

If several programs in your search path have the same name (for example, /usr/bin/who and /usr/local/bin/who), which reports only the first.

Filed Under: Linux

Some more articles you might also be interested in …

  1. Grsync: Graphical rsync backup tool in Ubuntu Linux
  2. cal: command not found
  3. How to Disable or set SELinux to Permissive mode
  4. CentOS/RHEL – How to run a script or command when any user logout the ssh session
  5. locate Command Examples in Linux
  6. whois Command Examples in Linux
  7. –force V/s –nodeps : rpm command options to install or uninstall a package
  8. How to Kill VNC Window Sessions in Linux
  9. How to Log dropped packets using firewalld in CentOS/RHEL 7
  10. How to enable IPv6 on CentOS / RHEL 6

You May Also Like

Primary Sidebar

Recent Posts

  • nixos-rebuild Command Examples in Linux
  • nixos-option: Command Examples in Linux
  • nixos-container : Command Examples in Linux
  • nitrogen Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright