Where is what - Printable Version +- nixers (https://nixers.net) +-- Forum: Operating Systems & Administration (https://nixers.net/Forum-Operating-Systems-Administration) +--- Forum: Servers Administration, Networking, & Virtualization (https://nixers.net/Forum-Servers-Administration-Networking-Virtualization) +--- Thread: Where is what (/Thread-Where-is-what) |
Where is what - venam - 05-06-2017 Hello fellow nixers, This thread is about this: Code: ~ > which which Let's list all possible ways to find out where a program is, be it built in or not, POSIX or not. RE: Where is what - evbo - 05-06-2017 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 RE: Where is what - xero - 05-06-2017 * note i'm truncating the output of these commands as an example * the posix way is to use "command": Code: [~]── - command -v 2bwm there's also "whereis": Code: [~]── - whereis 2bwm the "locate" command finds files by name: Code: [~]── - locate 2bwm but "which" is my favorite: Code: [~]── - which 2bwm you can use the "find" utility with the name flag: Code: [~]── - find -name 2bwm you 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 2bwm you can get the same results with ack, but it's much slower. Code: [~]── - ack -g 2bwm you 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 php if you use an "rpm" based distribution (centOS, rhel, SUSE, opensuse, etc): Code: [~]── - rpm -ql findutils if you use a "dpkg" based dist (debian, ubuntu and it's derivatives): Code: [~]── - dpkg --status some_package RE: Where is what - alxndr - 05-06-2017 Code: tree -f | grep '/firefox$' RE: Where is what - yossarian - 05-06-2017 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 ls I 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. RE: Where is what - venam - 06-06-2017 There seem to be a confusion with some users (neeasade and jkl). When I mentioned "not posix" I didn't mean "not Unix-like". RE: Where is what - jkl - 06-06-2017 Sorry, that was new to me. RE: Where is what - venam - 06-06-2017 (06-06-2017, 01:17 PM)jkl Wrote: Sorry, that was new to me.Neeasade had posted a whole "block" about some other OS too, don't be sorry about that. RE: Where is what - venam - 23-11-2021 A recent blog post reminded me of this: https://www.madebygps.com/an-intro-to-finding-things-in-linux/ RE: Where is what - neeasade - 29-11-2021 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/sh Then, in my 'wrapped' ~/bin/mpv, I can do something like: Code: og mpv \ RE: Where is what - z3bra - 29-11-2021 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' RE: Where is what - neeasade - 30-11-2021 The shell is bash, in a scripting context -- and the \ trick is a fair callout for escaping aliases in an interactive context for sure! |