Where is what - Servers Administration, Networking, & Virtualization
Users browsing this thread: 1 Guest(s)
|
|||
|
Hello fellow nixers,
This thread is about this: Code: ~ > which whichLet's list all possible ways to find out where a program is, be it built in or not, POSIX or not. |
|||
|
|||
|
I don't know if this is weird or not, but I usually forget about which and do the following:
Code: $ find / -name "which"And for fun, here's an example of how to not optimize a search: Code: #!/usr/bin/env python3 |
|||
|
|||
|
* note i'm truncating the output of these commands as an example *
the posix way is to use "command": Code: [~]── - command -v 2bwmthere's also "whereis": Code: [~]── - whereis 2bwmthe "locate" command finds files by name: Code: [~]── - locate 2bwmbut "which" is my favorite: Code: [~]── - which 2bwmyou can use the "find" utility with the name flag: Code: [~]── - find -name 2bwmyou also have other tools you can install to aid in your searching. "ag", the silver searcher, can search file contents (default) or file and location names with the -g flag Code: [~]── - ag -g 2bwmyou can get the same results with ack, but it's much slower. Code: [~]── - ack -g 2bwmyou can also search the inverse way looking for binaries by man page topics using "apropos": Code: [~]── - apropos "window manager"package managers can also give you some good info: on arch "pacman" can display a file install location list based on package name: Code: [~]── - pacman -Ql phpif you use an "rpm" based distribution (centOS, rhel, SUSE, opensuse, etc): Code: [~]── - rpm -ql findutilsif you use a "dpkg" based dist (debian, ubuntu and it's derivatives): Code: [~]── - dpkg --status some_package |
|||
|
|||
|
Code: tree -f | grep '/firefox$' |
|||
|
|||
|
I usually use bash's (POSIX) "command" built-in, since it catches aliases and functions in addition to normal utilities on the PATH:
Code: $ command -v lsI usually add a function like this to my scripts: Code: installed() {I used to use "which" for the same purpose, but the fact that OS X's version is slightly different was a source of great annoyance when scripting. |
|||
|
|||
|
There seem to be a confusion with some users (neeasade and jkl). When I mentioned "not posix" I didn't mean "not Unix-like".
|
|||
|
|||
|
Sorry, that was new to me.
-- <mort> choosing a terrible license just to be spiteful towards others is possibly the most tux0r thing I've ever seen |
|||
|
|||
|
|||
|
A recent blog post reminded me of this: https://www.madebygps.com/an-intro-to-fi...-in-linux/
|
|||
|
|||
|
tangently-related: Sometimes in my dotfiles I will wrap a program with some opinionated behavior (EG dmenu, or mpv). When that happens, I need a way to call the original program/fix the name collision. Enter the script `og`:
Code: #!/bin/shThen, in my 'wrapped' ~/bin/mpv, I can do something like: Code: og mpv \ |
|||
|
|||
|
I don't know which shell you're using, but you can do the same by prefixing the command with \ in most shells (even dash(1)):
Code: % alias ls='ls -l' |
|||
|
|||
|
The shell is bash, in a scripting context -- and the \ trick is a fair callout for escaping aliases in an interactive context for sure!
|
|||