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.

Is there a way on OS X to put flags at the end of a command instead of at the beginning? On my Ubuntu box, either of these will work, but OS X treats -la as a directory argument in the second example:

ls -la .
ls . -la

For this simple example, it's not that big of a deal, but it's frustrating when you miss a flag in a long command with lots of options/params and can't just hit up and add the flag to rerun the command.

I'm using Matias' OS X defaults, but I can't see anything in there that would change that behaviour.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This all depends on the program's implementation, or more specifically on how it parses options. OS X does not use the same implementation of ls — it uses the BSD versions thereof, while Ubuntu (and all Linuxes) use the GNU coreutils version.

Its behavior is not something you can change through a setting, but you can install the GNU coreutils through Homebrew:

brew install coreutils

That way, you could do the same thing on OS X. Note that in the default coreutils installation, all GNU utilities will be prefixed with g. So, you'd use gls instead of ls. You can override that behavior by adding them to your path. To do that, add this to your ~/.bash_profile:

export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"

That all being said—and because it all depends on the program implementation—you cannot expect this to work everywhere. Some programs are strict about where options appear, and others are not. It's nothing the OS itself enforces.

What you can also do to quickly add another option is to hit , CtrlA, Option. This will take you to the word after the command name itself, where you can add the option your forgot.

If it doesn't work and prints some weird characters when you press Option, make sure that these keyboard settings are enabled in Terminal.app's preferences under Settings » Keyboard:

share|improve this answer
    
Right, that makes sense, thanks for the info and suggestion about using the shortcuts. –  jjt Nov 10 '13 at 8:43
    
On a side note, it's interesting to see how that could potentially cause problems. Say you have a file called -rf, and you do a rm * in a folder. It'd remove the entire folder, including its subdirectories, although you only intended it to remove the files. That's why it's good practice to mark the end of options with --, or prefix globs with the current directory, for example: rm -f -- ./*. –  slhck Nov 10 '13 at 9:22

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.