How to get 'man gfind' when I enter 'man find'?
On my new-ish mac os/Darwin system, my find
tool is an 11-year-old BSD version. I have used MacPorts to install a more current version: GNU’s find
, which MacPorts has named gfind
, and placed in /opt/local/bin/
. The aging Apple-supplied find
remains in /usr/bin/find
.
I need to retain the old version of find
in the event that it’s still used by the system, but I’d much prefer to enter find
at the command line instead of gfind
. Old habits and all of that…
I know I can run gfind
when entering find
by either creating a link
in /opt/local/bin/
(it’s before /usr/bin
in my PATH), or by creating an alias
in .zshrc
. Both of these work fine. My problem is how to get man gfind
when I enter man find
– I’ve tried several versions of alias
in .zshrc
, but none have worked.
How do I get this to work? How do I get man gfind
in my pager display when I enter man find
at the command line?
If you do not need original find page – just make link from find.1.gz
to gfind.1.gz
Better, would be to edit MANPATH environment variable and put your own tree (man1, man2, etc) in it with a substitution of the man pages.
There’s a simple and general way to put all of the GNU (‘g-prefixed’) tools installed by MacPorts, and their associated manuals, on $PATH
in front of the native tools:
➤ The MacPorts package manager creates (& updates) a directory that contains symlinks to all of the GNU tools & manuals installed on MacOS; i.e. the "g-prefixed" tools:
/opt/local/libexec/gnubin
There are two (or more) sub-directories that contain the manuals. All of the files in these directories are symlinks to the GNU tools & manuals. For example:
lrwxr-xr-x 1 root admin 20 Dec 26 17:21 find -> /opt/local/bin/gfind
# under gnubin/man/man1 :
lrwxr-xr-x 1 root admin 36 Dec 26 17:21 find.1.gz -> /opt/local/share/man/man1/gfind.1.gz
If we check manpath
:
% manpath
/opt/local/share/man:/usr/local/share/man: /* etc. etc */
➤ And so we see that if we add /opt/local/libexec/gnubin
to $PATH, we will run gfind
when the find
command is entered, and we will view man gfind
when we enter man find
. The PATH may be modified by prepending gnubin
to the existing PATH:
export PATH="/opt/local/libexec/gnubin:$PATH"
If you’re happy with this, you can add this export
to your ~/.zprofile
. and you are done. No more re-training your fingers to type gfind
in stead of find
.
➤ You can also tailor this easily:
Many of the GNU tools are packaged as a "set", meaning that gfind
is packaged with several other tools in the Findutils package – which includes glocate
. I was OK with this until I learned that there is a stubborn bug in gupdatedb
that effectively disables it (and thereby renders glocate
useless) – owing to some diffs between Darwin & Linux.
I use the native locate
occasionally, and wanted to avoid wasting any further time on the GNU version. The "fix" for this is to unlink
the symlinks to glocate
, gupdate
and their associated manuals from /opt/local/libexec/gnubin
.
➤ But there is one more kink to sort if you "tailor" gnubin:
I learned that MacPorts periodically updates /opt/local/libexec/gnubin
, and have been informed by one of the maintainers that these updates will "repair" my modifications! This adds only one step to the solution: copy the original gnubin
folders to another location; make all edits (unlink
s) to that alternate location and use it in the PATH. Here’s how to do that:
% sudo cp -RPp /opt/local/libexec/gnubin/ /opt/local/libexec/gnubin-m
Note that this is the native, BSD version of cp
➤ The final solution – edit/unlink gnubin-m & add to PATH
% sudo unlink /opt/local/libexec/gnubin-m/locate
% sudo unlink /opt/local/libexec/gnubin-m/man/man1/locate.1.gz
...
export PATH="/opt/local/libexec/gnubin-m:$PATH"