0

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?

2 Answers 2

2

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.

2
  • Did you check this on a mac? I have no MANPATH environment variable.
    – Seamus
    Commented Jun 11, 2022 at 6:48
  • If you do no have it - create it. Do man man for better understanding.
    – White Owl
    Commented Jun 11, 2022 at 14:01
0

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 (unlinks) 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"

5
  • Note that with zsh, you'd rather do path=(/new/dir $path) or path[1,0]=/new/dir to insert a new dir at the start of $PATH. Commented Jun 13, 2022 at 8:53
  • I didn't know zsh had a different syntax for modifying $PATH - thanks, I'll look into that. It does work as shown though... is there an advantage of the proper syntax?
    – Seamus
    Commented Jun 13, 2022 at 9:10
  • PATH=/new/dir:$PATH will also work, it's just that in zsh, like in (t)csh, $PATH is mapped to the $path array, and it makes more sense to manipulate it as a list. Commented Jun 13, 2022 at 9:12
  • @StéphaneChazelas: I'm sure you're correct, but having a difficult time finding much in the zsh documentation. I did find this, but it's not yet sunk in. Do you have other references?... I'd like to read more on the details.
    – Seamus
    Commented Jun 13, 2022 at 9:30
  • 1
    See info zsh path or info zsh PATH assuming the documentation is installed in info format. You'll also find it in the man pages, though man is not adapted for a manual this big. Commented Jun 13, 2022 at 9:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .