For example, when I entered either:
gcc -O hello.c -c
gcc hello.c -c -O
Both did not complain.
Does the order of command options matter?
This depends on the program itself; the operating system doesn't dictate whether or not order matters.
GCC's set of options is so colossal that I can't say with any authority if you can supply any option in arbitrary order; you'll have to read the documentation for that option. That said, a general rule of thumb is that if you have two or more mutually exclusive options (such as
A simple program that does let you specify most options in any order would be
There is also the odd program which applies options to arguments as they arrive. So, for example, you might have a hypothetical command
Again, this is up to the individual program in question. If you're ever unsure, read the documentation.
There are cases where the order of command line options matters even in GCC. If you are linking with static libraries (.a), then if you specify
In general, as others said, the order of the options may or may not make a difference. However, the output from the two commands below are different - so the order of the arguments to
Note also that on Linux (in particular), GNU
Hard to know, as other already told you it may make a difference (or not).
A good rule of thumb is to open the man page and look at the first example and use that order when putting the arg in there.
So if we look at the cat command (man cat):
It seems like as long as all the options are before the file args you should be fine.
And if we look at the gcc beast (man gcc):
It is not that simple to understand as the cat command :)
But if you would like to play it safe, -c seems to come before -O and then infile (hello.c) seems to be last.
But as you already know, since the others work... this is playing it very safe :)
Only if you have 2 options that are mutually exclusive. Otherwise, order does not matter.
Of course, this can vary depending on how the program has been written, but should apply to all normal *nix tools.