I'm new to Mac usage. It seems that most commands trip over options given after the file names. In linux, which I've used for years, it doesn't matter. On Apple, it does. Is there some setting somewhere or some hack to make commands like ls behave "normal"?

dwilson 0====> ls -l p*
-rw-r--r--@ 1 dwilson  owner  184 Jul 29 13:57 poo.c
-rw-r--r--@ 1 dwilson  owner  133 Jul 29 13:57 poo.h

dwilson 0====> ls p* -l
ls: -l: No such file or directory
poo.c        poo.h

dwilson 1====>
  • Did you have zsh and a customized environment on linux? You might need to just set that up to get more permissive ordering of arguments. That would make my brain hurt, but if you are used to it - disruptive to change on the mac. – bmike Jul 29 '11 at 21:09
  • The Mac uses tcsh, which I don't use much. Maybe it's bash that's responsible for ls being so freely reorderable. – DarenW Jul 30 '11 at 5:40
  • The man page for ls clearly shows all arguments must precede the first file. Only the shell could glob the wildcard and sort the arguments first. Hopefully you can identify the linux settings for that shell and migrate those .files to mac. – bmike Jul 30 '11 at 15:40

The reason for this is that Mac OS X uses BSD utils (which have a specific order to their parameters), whereas Linux uses the GNU utils, which can accept arguments in any order.

You can download and compile the GNU coreutils package, which should provide you with the utilities you're used to; I would recommend just getting used to the BSD utils, however, as you'll otherwise have problems moving to other systems. The BSD method works fine on GNU systems, but the GNU method is less portable.

  • 2
    I recommend getting Homebrew and installing the GNU coreutils, because they are much more feature-rich than the ones that Mac OS X includes. It's one of the first things I do when setting up a new Mac because I spend a lot of time at the command line and I want the best tools available. Note you'll need Xcode to compile Homebrew and other utilities. Otherwise you might want to checkout Rudix which offers pre-compiled binaries of many popular Unix utilities. – TJ Luoma Dec 22 '11 at 20:53

If you are using MacPorts (and as a Linux connoisseur you probably are), you can install GNU coreutils with:

sudo port install coreutils

and then make sure to add the coreutils path to your path:

export PATH=/opt/local/libexec/gnubin:$PATH

[Sources: TJ Luoma comment to the accepted answer and this blog post.]


The example you have given is normal. I know of no *nix environment that will take flags/options after the file list for ls

Some commands are just different versions from whichever *nix environment you are coming from. You can fix things like this by using alias or other shells.

  • That's no problem in the *nix environments I've come in contact with. Weird example though. tail is more interesting, for example tail -f file -n 200 doesn't work as expected in OSX. – Frans Jan 9 '15 at 22:19
  • @frans The -f in tail -f means "follow", not "file", so it doesn't take a filename as a second parameter. This behavior is consistent for all Unix systems which adhere to the options-before-filenames convention. – nohillside Jan 12 '15 at 16:12
  • Ha! Yeah, I actually knew that, I just experienced some kind of brain melt. Well, after installing coreutils I now get the same functionality as on Ubuntu, where tail -f file -n 200 works, so I'm happy. – Frans Jan 13 '15 at 6:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .