Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.3: ls date format switched from previous releases UNIX
I am a UNIX programmer. Some time ago, I found a need to create a utility that would filter the results of the ls command by date. It is actually a combination of a bourne shell script and a C++ program which filters the output of the ls command by date or date range. This has worked for me for quite a long time from A/UX 3, through HP/UX 9 and 10, AIX 4 and Mac OS X 10.2. Strangely it is now broken in Mac OS X 10.3, Panther. The reason is a completely unnecessary change to the formatted output of the ls command. On Jaguar, 10.2.8, the ls output looks like:
  drwxr-xr-x   5 root      admin      170 Dec 26 21:36 grp
while on Panther it looks like:
  drwxr-xr-x   5 root      admin      170 26 Dec 21:36 grp
For reasons unknown, someone at Apple decided to reverse the order of the month and the day. As I said, I have not seen this on four other UNIXs nor one previous version of Mac OS X. It is apparently not related to the International settings in System Preferences (both were set to United States), nor is it related to a brand new machine (my iMac is less than a month old and came with 10.3.1), nor the installation of 10.3 over an existing 10.2.8 on a friend's Mac.

For those like me out there who have various utilities that utilize the dates output by the ls command, Apple has generated some unnecessary work for us. Beware, there may be other hidden oddities as well.
    •    
  • Currently 1.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[12,805 views]  

10.3: ls date format switched from previous releases | 14 comments | Create New Account
Click here to return to the '10.3: ls date format switched from previous releases' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: ls date format switched from previous releases
Authored by: cynikal on Jan 20, '04 11:25:03AM

perhaps you're unaware of this since you wrote your own script but.. ls has a built in sort-by-date flag.. i won't be a prick and say man ls though perhaps you should have :)

if you do -t it will sort with more recent dates at top, and oldest dates at the bottom..

there's even a way to reverse this sort, you guessed it, -r

oh and in case you want to sort by size, i didn't see a built in flag, but this works pretty well

ls -l|sort -n +4 (add -r to sort if you want reverse order and if you're interested only in files, pipe it into grep ^- before sort)

in any event, i agree with you that it's strange that apple would have done this weird modification of ls for no real reason.



[ Reply to This | # ]
10.3: ls date format switched from previous releases
Authored by: LC on Jan 20, '04 01:58:38PM
Don't forget sticky bit where the 1st char column is "t", fix your exp

[ Reply to This | # ]
10.3: ls date format switched from previous releases
Authored by: hopthrisC on Jan 20, '04 04:01:15PM
Wrong! The sticky flag is displayed as follows (see the man page):
                These next two apply only to the third character in the last
                group (other permissions).

                      T     The sticky bit is set (mode 1000), but not execute
                            or search permission.  (See chmod(1) or
                            sticky(8).)

                      t     The sticky bit is set (mode 1000), and is search-
                            able or executable.  (See chmod(1) or sticky(8).)


[ Reply to This | # ]
10.3: ls date format switched from previous releases
Authored by: LC on Jan 20, '04 04:17:07PM

Yeah right, it's at the right end, not the left (I forgot;) Larry.



[ Reply to This | # ]
10.3: ls date format switched from previous releases
Authored by: jctull on Jan 20, '04 12:38:26PM

My ls -l output is still Month followed by day. I am using the bash shell, but the same goes for tcsh. No matter, mine is the way it always has been. It looks like one of our other Panther machines is as you describe, so there must be a default that I have overridden somehow.



[ Reply to This | # ]
10.3: ls date format switched from previous releases
Authored by: LC on Jan 20, '04 02:00:19PM
We are talking about /bin/ls and not a shell built-in;

[ Reply to This | # ]
10.3: ls date format switched from previous releases
Authored by: LC on Jan 20, '04 02:23:49PM
Now (10.3.x on my system), the date format from /bin/ls does not match that used by the "-ls" primary of /usr/bin/find. And, find's man page says it's equivalent to ls -dgils which now seems to be slightly in question. Anyone seen a change note from Darwin on this? (By the way, that date line was never fully important for script parsing since items showing a very new or very old date don't have any day displayed ... perl's stat() is always handy;) Larry.

[ Reply to This | # ]
10.3: ls date format switched from previous releases
Authored by: hopthrisC on Jan 20, '04 03:58:39PM
You are a "UNIX programmer"? Right... Look what the output of my ls looks like:
aschenputtel:~ hop$ ls -l
insgesamt 0
drwxr-xr-x    4 hop      hop           136 18. Jan 21:59 Applications
drwxr-xr-x    4 hop      hop           136 21. Jun 2003  CVS
drwx------   59 hop      hop          2006 20. Jan 00:49 Desktop
drwx------   23 hop      hop           782 18. Jan 20:48 Documents
drwx------   35 hop      hop          1190 20. Jan 21:47 Library
That is the output of GNU ls, granted, but to quote from the man page of BSD ls:
     LANG            The locale to use when determining the order of day and
                     month in the long -l format output.  See environ(7) for
                     more information.



[ Reply to This | # ]
10.3: ls date format switched from previous releases
Authored by: LC on Jan 20, '04 05:17:08PM
There actually is a dual-mode behavior to /bin/ls. I did a "strings" on the executable and found both
"%e %b" and "%b %e" in it ... then I looked at the FreeBSD source (of ls) and saw stuff like --
d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
format = d_first ? "%e %b %Y " : "%b %e %Y ";
in it ... and in /usr/include/langinfo.h on your system, it'll say --
#define D_MD_ORDER 57 /* month/day order (local extension) */
So it has something to do with D_MD_ORDER in the locale; Larry.

[ Reply to This | # ]
10.3: ls date format switched from previous releases
Authored by: LC on Jan 20, '04 05:48:29PM
O.K. I think I get it now, md_order is defined in timedef of the locale source, for example --
#
# md_order
#
md

So, some of the locales in use probably have "dm" which is triggering that "d_first" in /bin/ls.
If I can dump 'em or figure out which one(s), I'll post here. Larry.

[ Reply to This | # ]
10.3: ls date format switched from previous releases
Authored by: LC on Jan 20, '04 06:11:37PM
I grep'ed all of the LC_TIME files under /usr/share/locale and most of them specify "dm"
as the month-date order, which is probably what's stimulating /bin/ls to do that. But the USA and Canada English
locales do specify "md". I checked both my Date (time zone) and International System Preferences panels and those
settings looked o.k.; so I'm still wondering which preference file is throwing off my current locale setting and so ls. Larry.

[ Reply to This | # ]
10.3: ls date format switched from previous releases
Authored by: fenner on Jan 20, '04 08:44:45PM

Due to a error introduced when porting the locale code, ls doesn't look at the order field; it always uses "dm". You're not going to find a preference to change it because it's a bug.



[ Reply to This | # ]
10.3: ls date format switched from previous releases
Authored by: fenner on Jan 20, '04 08:38:26PM
This is an internationalization bug in 10.3. If you download the source, you'll see that Apple added

#ifndef __APPLE__
        crucial internationalization code here;
#endif
to the code as ported from FreeBSD -- meaning that the crucial code doesn't get executed on MacOS. I submitted radar #3473836 for this issue; it's been in Verify state for a while, so hopefully it'll be in an OS update soon.

[ Reply to This | # ]
10.3: ls date format switched from previous releases
Authored by: LC on Jan 20, '04 10:06:37PM

Great info, thanks a lot Bill! Larry.



[ Reply to This | # ]