The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 8,854β€…    Votes:  2β€…
Tags: command-line   bash  
Link: πŸ” See Original Answer on Ask Ubuntu ⧉ πŸ”—

URL: https://askubuntu.com/q/1051333
Title: How to get the location of a program in Ubuntu terminal?
ID: /2018/07/01/How-to-get-the-location-of-a-program-in-Ubuntu-terminal_
Created: July 1, 2018    Edited:  June 12, 2020
Upload: September 15, 2024    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


As David Foerster already mentioned, you can use type -a which will show all the locations a given executable can be found in the active $PATH:

$ type -a now
now is /home/rick/bin/now
now is /mnt/e/bin/now

type -a will also identify if the command is a shell built-in. For example:

$ type -a test
test is a shell builtin
test is /usr/bin/test

type -a will also identify if the command is a shell keyword. For example:

$ type -a if
if is a shell keyword

type a lists programs, commands, shell built-ins and shell keywords in the hierarchal order they would be called depending on the $PATH environment variable. By changing PATH= to a different order it changes which version of the program is called. This is handy when you have production, development and test program versions on the same machine.

Program isn’t in $PATH

What if the program isn’t in your path? The fastest way of finding it is with the locate command:

$ locate .bashrc
/etc/bash.bashrc
/etc/skel/.bashrc
/home/rick/.bashrc
/home/rick/.bashrc~
/mnt/e/.bashrc
/mnt/e/Temporary Work/.bashrc
/usr/share/base-files/dot.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/bash.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/skel/dot.bashrc

I kind of cheated here because .bashrc isn’t a real executable, it’s a β€œsource” file to include in a bash script which is an executable. However it serves to illustrate appropriately.

⇧ Lowering screen max brightness with Ubuntu 18.04 External hard drive keeps powering down  β‡©