Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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====>
share|improve this question
    
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
add comment

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer
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
add comment

The example you have given is normal. I know of no *mix 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 form. You can fix things like this by using alias or other shells.

share|improve this answer
add comment

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.]

share|improve this answer
add comment

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.