It's no secret that Mac OS X is based on BSD, and, as a result, I inherited a complete set of BSD shny command line utilities, such as ls, find, xargs, and many others. They are good and correct, and it is quite possible to use them - however, if you have been using Linux for a long time, you must have gotten used to the GNU versions of these utilities, that is, for example, the
---
, the normal option -
---
- and you have developed habits. I also belong to the number of such people, and when I needed to recruit a couple of dozen commands in Terminal.app, after 10 minutes I began to
tear my chest hair and read the man, which did not contribute to labor productivity.
Somewhat later, I thought - why, in fact, I cannot use the GNU versions of the utilities - just because they are not supplied with the system? No, this is not a UNIX way!
A few minutes of searching confirmed my suspicions, and I found the versions of the utilities I needed on
GNU coreutils . Now the question was how to install them.
In general, I had two options:
- Build them from source yourself
- More civilized - use MacPorts, which is a completely normal package manager.
I preferred to use the second method, although this is a personal matter for everyone :-)
So, a brief MacPort installation guide can be found
on the official website - the process is extremely simple and straightforward, you only need to have Apple Developer Tools installed (xcode in particular).
After MacPort is installed, in the simplest case, you need to execute just one command in the terminal:
sudo port install coreutils
Why in the simplest case? The fact is that MacPort does not overwrite file utilities by default, and installs its versions in a separate directory with a different name:
/ opt / local / bin / g ls instead of / usr / bin / ls
/ opt / local / bin / g find instead of / usr / bin / find
...
You can solve this problem in several ways, choose a specific one - everyone’s business, I’ll just list them.
- The easiest way is to install coreutils with the with_default_names option:
sudo port install coreutils + with_default_names
In this case, the utilities will be overwritten by default. I would not recommend using this method, since the system as a whole may not appreciate if system utilities are replaced, albeit with compatible ones, but still other programs. - The second option is to rename the default utilities and add links to new programs:
mv / usr / bin / ls / usr / bin / mls
ln / opt / local / bin / gls / usr / bin / ls
In this case, the original versions of the utilities will be available by name with the prefix “m”. This is also not the best way, since according to / usr / bin / ls all programs without exception will receive the GNU version of the utility. - The third way is ideologically the most consistent. It is that links are created without the “g” prefix, but in
/opt/local/bin
ln / opt / local / bin / gls / opt / local / bin / ls
and then in your local ~/.bashrc
you add this path to your PATH before /usr/bin
: export PATH = / opt / local / bin: $ PATH
Alternatively, you can create links in general in a separate directory, and prescribe it before $ PATH. In this case, only you, and only working with your favorite shell (which, by the way, can also be installed from macport), will use the GNU version of the utilities. All other programs and people will not even guess their existence, and will use standard BSD-compatible fileutils. - The fourth option, advised by the haber man, gribozavr (and shame on my gray hair, that I myself hadn’t thought of it before) is to do alias:
alias ls = '/ opt / local / bin / gls'
and add this to your ~ / .bashrc
Thus, we get a fully GNU-version of command utilities - which will be very convenient for Linux users who, on duty or mental urge, use a Mac (I proudly consider myself to be the last).