GNU command line utils

    It's no secret that Mac OS X is based on BSD, and as a result, inherited a full set of BSD-based 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 used Linux for a long time, you are probably used to the GNU versions of these utilities, that is, for example --длинным-аргументам, the normal --help option - well, you have developed certain habits. I also belong to such people, and when I needed to type a couple of dozen teams at Terminal.app, after 10 minutes I started to tear my chest hair and get nervous and read man, which did not contribute to labor productivity.
    A little later, I thought - why, in fact, I can’t use the GNU version of utilities - just because they do not come with the system? No, this is not a UNIX way!

    A few minutes of searching confirmed my suspicions, and the versions of utilities I needed were found on GNU coreutils . Now the question was how to install them.
    In general, I had two options:
    • Build them from source yourself
    • More civilized is to use MacPorts, which is a completely normal package manager.

    I preferred to use the second method, although this is everyone’s personal business :-)
    So, a brief installation guide for MacPort can be found on the official website - the process is extremely simple and straightforward, you just need to have Apple Developer Tools installed (xcode in particular).
    After MacPort is installed, in the simplest case, you only need to execute one command in the terminal:
    sudo port install coreutils

    Why in the simplest case? The thing 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
    ...

    There are several ways to solve this problem; choosing a specific one is everyone’s business; I’ll just list them.
    1. The easiest 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 the system utilities will be replaced even with compatible ones, but still other programs.
    2. 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". Also not the best way, because with / usr / bin / ls all programs without exception will get the GNU version of the utility
    3. The third method is ideologically the most seasoned. It consists in the fact that links are created without the prefix "g", but in/opt/local/bin
      ln / opt / local / bin / gls / opt / local / bin / ls
      then in your local ~/.bashrcyou add this path to PATH before/usr/bin :
      export PATH = / opt / local / bin: $ PATH
      Alternatively, you can create links in general in a separate directory, and write 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 utilities. All other programs and people will not even guess about their existence, and will use standard BSD-compatible fileutils.
    4. The fourth option advised by the grubozavr man gribozavr (and a shame on my gray hair that I myself had not thought of this before) is to make alias:
      alias ls = '/ opt / local / bin / gls'
      and add this to your ~ / .bashrc

    Thus, we get a fully GNU version of the command utilities - which will be very convenient for Linuxoids who use a Mac for duty or sincere desire (I proudly rank myself among the latter).

    Also popular now: