I've found an easy way to dig up commands that I can't alltogether remember. While installing an operating system recently, I forgot which command I needed to invoke from the shell which would allow me to configure locales. Using this code I was able to find "tzconfig" on the Debian box I was setting up. *This won't work in most non-*nix environments (eg- DOS). It requires the presence of the "grep" and "ls" commands from within your shell. Obviously, Perl needs to be installed too.
#!/usr/bin/perl -w use strict; use warnings; my($cmd) = shift @ARGV || die <<__MORT__; Nothing to search for. Invoke this program with the command name or p +art of the command name for which you want to search in your \$PATH. usage: $0 [command to search for in \$PATH] __MORT__ foreach (split(/:/,$ENV{'PATH'})) { print qq[IN "$_"\n], (`ls ${\quotemeta $_}|grep $cmd`||"[none]\n"), + "--\n\n" }

Replies are listed 'Best First'.
Re: find a forgotten shell command
by dominix (Deacon) on Jan 07, 2004 at 02:10 UTC
    you could write it completely in perl. Perl provide a powerfull grep to catch over list and many file access method thru File::* or simply glob() like
    perl -le '$cmd="ls";foreach (split(/:/,$ENV{"PATH"})){print grep(/$cmd +/, glob("$_/*"))} '
    You could get inspired by the already made (in perl) unix command from PPT project to produce more granulated output.
    --
    dominix

      Yep you are right. I didn't think of using glob, but I do know that Perl has a CORE::grep(). Nice job.

      But to which "already made (in perl) unix command from PPT" do you refer?

      --
      Tommy Butler, a.k.a. TOMMY
      
        in that case ls and grep (the only non perl things of the original script)
        --
        dominix
Re: find a forgotten shell command (use apropos)
by grinder (Bishop) on Jan 07, 2004 at 09:10 UTC

    Nice hack. In case you weren't aware, there is also the command apropos at your disposal to find forgotten (or unknown!) commands relating to a specific subject.

    It works by examining commands for which man pages exist, and scans the one-line explication of the command. apropos, then, simply greps for your text among the resulting data set. (Of course, it's all built ahead of time to make searches faster).

    None of the machines here (Solaris, FreeBSD, Linux...) have a thing called 'tzconfig', so I can't decide whether this would have helped, but there you are.

      `apropos` is not to find "forgotten (or unknown!) commands", but rather a manual page relating to a specific subject. On my machine, `tzconfig` doesn't have a manual page (it's nothing more than a shell script), so nothing will show up.

      But why not use `locate` with a grep on bin? In this specific example (tzconfig), that helped me more than this perl snippet, since "/usr/sbin" is not in my $PATH.

      $ locate tzconfig | grep bin /usr/sbin/tzconfig

      Or if you know you've recently used the command, `history` will guide you, and if you know the first n letters of your command, and the application is in your path, a double [Tab] will do just fine :)

      # tz[Tab][Tab] tzconfig tzselect # tz
      --
      b10m