Making OS X Command Line Behave More Like Linux (GNU)

March 4th, 2009 | by Jeff Fitzsimons |

The command-line oddities of Mac OS X’s BSD heritage drive me insane. I much prefer the behavior of the GNU toolchain, as provided by Ubuntu Linux.

To begin, first install MacPorts.

MacPorts Installation Variant +with_default_names

With several MacPorts packages, the +with_default_names variant may be specified. This causes package contents to be installed without the default “g” prefix. For example, without +with_default_names, find would be installed as gfind.

Autocompletion

I like Ubuntu’s command line autocompletion. For example, typing rsync --pro" and pressing tab will result in rsync --progress.

1) Use MacPorts to install the bash-completion package:

sudo /opt/local/bin/port install bash-completion

2) Edit ~/.bash_profile to load the correct autocompletion script:

if [ -f /opt/local/etc/bash_completion ]; then
   . /opt/local/etc/bash_completion
fi

Open a new terminal window, and commands should auto-complete according to the GNU specification.

Find

The GNU version of find automatically assumes that, if no arguments were given, you wish to search the current directory. The OS X (BSD) version simply craps its pants and does nothing if a directory isn’t specified.

sudo /opt/local/bin/port install findutils +with_default_names

This package includes find, gfind, glocate, goldfind, gupdatedb, gxargs, locate, oldfind, updatedb, and xargs.

Core Utilities

This vaguely-named package provides a large number of standard GNU tools. See below for a complete list.

sudo /opt/local/bin/port install coreutils +with_default_names

This package includes [, base64, basename, cat, chcon, chgrp, chmod, chown, chroot, cksum, comm, cp, csplit, cut, date, dd, df, dir, dircolors, dirname, du, echo, env, expand, expr, factor, false, fmt, fold, g[, gbase64, gbasename, gcat, gchcon, gchgrp, gchmod, gchown, gchroot, gcksum, gcomm, gcp, gcsplit, gcut, gdate, gdd, gdf, gdir, gdircolors, gdirname, gdu, gecho, genv, gexpand, gexpr, gfactor, gfalse, gfmt, gfold, ggroups, ghead, ghostid, gid, ginstall, gjoin, gkill, glink, gln, glogname, gls, gmd5sum, gmkdir, gmkfifo, gmknod, gmktemp, gmv, gnice, gnl, gnohup, god, gpaste, gpathchk, gpinky, gpr, gprintenv, gprintf, gptx, gpwd, greadlink, grm, grmdir, groups, gruncon, gseq, gsha1sum, gsha224sum, gsha256sum, gsha384sum, gsha512sum, gshred, gshuf, gsleep, gsort, gsplit, gstat, gstty, gsum, gsync, gtac, gtail, gtee, gtest, gtouch, gtr, gtrue, gtsort, gtty, guname, gunexpand, guniq, gunlink, guptime, gusers, gvdir, gwc, gwho, gwhoami, gyes, head, hostid, id, install, join, kill, link, ln, logname, ls, md5sum, mkdir, mkfifo, mknod, mktemp, mv, nice, nl, nohup, od, paste, pathchk, pinky, pr, printenv, printf, ptx, pwd, readlink, rm, rmdir, runcon, seq, sha1sum, sha224sum, sha256sum, sha384sum, sha512sum, shred, shuf, sleep, sort, split, stat, stty, sum, sync, tac, tail, tee, test, touch, tr, true, tsort, tty, uname, unexpand, uniq, unlink, uptime, users, vdir, wc, who, whoami, and yes

Post a Comment