Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I wonder if the unix commands (cp, mv, grep, args etc) are the same for Mac and Ubuntu.

Do they have the same parameter lists and so on or do they try to stay the same but are slightly different?

share|improve this question

3 Answers 3

up vote 7 down vote accepted

The basic commands and options are the same, but each implementation provides its own additional commands and options.

Since shortly after the birth of Unix, there have been several flavors of Unix sharing a basic command set but each with their own extensions. Implementers regularly grab features from one another, so if system X introduces a new option, it may become available in system Y after a few years.

Eventually, the POSIX specification was elaborated to standardize on a common subset of features. This standard is currently managed by the Open Group. Although the current version of the standard is Single Unix version 4, most systems only implement version 3. On Ubuntu, the susv3 package contains the Single Unix version 3 specification. This is a reference document, so it can be a stiff read, but it can be useful at least to check whether an option you already understand is standard.

There are POSIX-conforming tools for most desktop/server operating systems. Anything unix-based (Linux, Solaris, *BSD, OSX, ...) has them natively. The native utilities on Linux are the GNU utilities. Several implementations exist for Windows, including Microsoft's Services for Unix and ports of GNU utilities such as cygwin and GNU Win32 utilities.

share|improve this answer

OS X (Darwin) uses BSD versions of the standard tools. Ubuntu (and Linux in general) uses GNU versions. They are very similar, but the differences (such as presence and order of options) can trip you up if you're not careful.

share|improve this answer
3  
When in doubt, use the --help option or RTFM –  Doug Harris Aug 21 '10 at 12:47

They are different enough that (1) you cannot rely on them being the same, (2) it will drive you crazy at times and (3) you really should carefully test any script you plan to use on both systems.

The way I usually handle all this is to install the GNU coreutils and find and use those versions in preference to the Mac ones. You can install the GNU versions via one of the *nix packaging tools for OSX:

Those are listed in my order of preference, but you should investigate to see which will fit your needs best.

share|improve this answer
    
Installing these commands is great for your own use, but it makes software distribution much harder, because most people who get your software don't have the tools installed. –  vy32 Aug 21 '10 at 16:58
    
@vy32 Depends on who you're distributing to. If you're writing tools for other developers, I disagree. And, frankly, if you're writing command-line tools of any sort, I'm not so sure I agree. All the people I know who use the command line regularly on OSX use one or another of these package managers. –  Telemachus Aug 21 '10 at 20:13
    
If you are working on a disconnected network you can't use a package manager. If you are preparing a live CD you can't use a package manager. If you are building packages that are used by package managers, you can't use a package manager. –  vy32 Sep 17 '10 at 12:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.