How does Mac's command line compare to Linux?

I love Ubuntu Linux - especially the commmand line. But I have to admit that, at least for now, Windows is more user-friendly - there's more software for it, more drivers, and more stuff just works.

Knowing that Mac is built on Unix makes me wonder if it's the sweet spot between them. But I wonder: how similar is the Mac command line to Linux's bash? Could I pick right up with using vim and bash scripting and git, etc? Would common commands like changing directories be different? Does anybody know an online "compare and contrast" resource?


Solution 1:

Bash is bash so the shell and its built-ins are the same. But be aware that the behavior of some tools like ps or head can differ in the details thus your scripts might fail.

Solution 2:

Mac OS X is a Unix OS and its command line is 99.9% the same as any Linux distribution. bash is your default shell and you can compile all of the same programs and utilities. There's no notable difference. You can also find various projects like MacPorts which provide package management for Mac.

Solution 3:

It's very similar, but if you know of any BSD v. Linux differences, expect the Mac to have the BSD behavior.

Solution 4:

A couple things - it really depends on what you mean by command line.

  1. You'll probably run bash, which will be the same as bash on any other UNIX. The bash programming language will be the same too - as long as it's the same version. Bash versions have slight differences in the language, but this has nothing to do with MacOSX vs. Linux per se.

You may actually bump into this - /bin/bash on a Mac is pinned to 3.x for licensing reasons. You may find minor compatibility issues if you’re used to 4 or even 5.

  1. bash by itself is a small subset of 'command line'. To be useful you typically use some other common UNIX utilities such as awk, or ls, or cut. Because of its history (it's descended from BSD, not Linux or SystemV), the Mac versions of utilities will be different than the ones you're used to on Linux (a.k.a. GNU versions). These will have at least some flag differences, and some output and functionality differences than Linux. Scripts that use these will have to be changed to compensate. BSD awk vs GNU gawk is pretty different. OR, you can get these GNU versions from macports or home brew, and set your PATH so that these are the defaults (over the built in versions).

  2. MacOS X also has some new cool tools. open is nice, it will open the object as if you double clicked it. defaults allows you to set some preferences, some not even in the GUI preferences panels. textutil can be useful and say can be fun.