Why does ls ignore command line argument order?

I'm using ls -l in a tcsh shell to get information about a file and a symbolic link. Independent of the order they are specified on the command line, the file is always listed first. Why is this? i.e., why do these two commands produce the same output?

Code:
# ls -l jquery.dataTables.js /web/include/jquery.dataTables.js
-rw-r--r--  1 fkeinternet  fkeinternet  447282 Jul 26  2016 /web/include/jquery.dataTables.js
lrwxr-xr-x  1 fkeinternet  fkeinternet      33 May 31 01:29 jquery.dataTables.js -> /web/include/jquery.dataTables.js

# ls -l /web/include/jquery.dataTables.js jquery.dataTables.js
-rw-r--r--  1 fkeinternet  fkeinternet  447282 Jul 26  2016 /web/include/jquery.dataTables.js
lrwxr-xr-x  1 fkeinternet  fkeinternet      33 May 31 01:29 jquery.dataTables.js -> /web/include/jquery.dataTables.js

Operating environment:
Code:
# pwd
/web/<client_directory>/www/include

# uname -a
FreeBSD Dreamer 11.1-RELEASE-p4 FreeBSD 11.1-RELEASE-p4 #0: Tue Nov 14 06:12:40 UTC 2017     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64
# tcsh --version
tcsh 6.20.00 (Astron) 2016-11-24 (x86_64-amd-FreeBSD) options wide,nls,dl,al,kan,sm,rh,color,filec
 
From the output of "man ls": If no operands are given, the contents of the current directory are displayed. If more than one operand is given, non-directory operands are displayed first; directory and non-directory operands are sorted separately and in lexicographical order.

Look at the option "-f", it turns sorting off.
 
Why does it matter?

Because I'd like to understand what's going on, if for no other reason. I was in the middle of trying to figure out some other odd behaviour and found this confusing when it popped up: I expected the results to be in the order I entered the filespecs.

Anyway the explanation is in the man page:

I have to admit, I didn't first look at the man page, I did a Google search for "freebsd ls ignore command line argument order" which didn't yield any useful results. Clearly I was looking in the wrong place, perhaps if I wasn't so busy trying to figure out why two symlinks originating and ending in the same directories (different files) behaved differently I would have thought to look at the man page.

Thanks all for the RTFM reminder!!
 
Actually, it's worse than that: I think the -f and -a flags (and their side effects) are defined by the Posix standard.

Actually, if you want the functionality of the ls command without the "-l" flag and without sorting, you can just use echo and command line globbing: "echo c* b* a*" in a directory that contains file adam, bella, bob and charlie would just output the words "charlie bella bob adam", which might be closer to what you want.
 
Back
Top