Computing.Net > Forums > Unix > Date display from ls -l command

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Date display from ls -l command

Reply to Message Icon

Name: Carl Hoog
Date: July 14, 2003 at 08:02:04 Pacific
OS: HP-UX
CPU/Ram: Not relevent
Comment:

When doing a ls -l command, the date for recently modified files appears as, for example, Jul 9 17:03. For much older files, it appears as, for example, Feb 7 2002. Does anyone know what controls this and can it be manipulated in a given session so that all appear as MMM DD YYYY or some other selectable format the includes the year? I want to do a ls -lt and capture the date stamp of the oldest file into a shell variable. I need it to always be in the same format and to include the year.



Sponsored Link
Ads by Google

Response Number 1
Name: WilliamRobertson
Date: July 14, 2003 at 10:30:17 Pacific
Reply:

From "man ls":

"If the time of last modification is greater than six months ago, it is shown in the format 'month date year' for the POSIX locale. When the LC_TIME locale category is not set to the POSIX locale, a different format of the time field may be used. Files modified within six months show 'month date time'."

Unfortunately I don't see any options or settings for changing this behaviour. Looks like an interesting scripting project...



0

Response Number 2
Name: nails
Date: July 14, 2003 at 10:54:30 Pacific
Reply:

Hi:

William is right about the 6-months time thing. I've used this code snippet, but it probably has a problem from Jan thru June, but it's a start:

year=$(date +%Y)

ls -l | nawk -v year=${year} '
{ printf("%s\n", index($(NF-1), ":") ? year : $(NF-1));
}

Regards,

Nails


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Date display from ls -l command

retrieve DD/MM/YY HH:MI file information www.computing.net/answers/unix/retrieve-ddmmyy-hhmi-file-information/2761.html

Display file date as a 3 digit day www.computing.net/answers/unix/display-file-date-as-a-3-digit-day/6610.html

copy files with pattern from a file www.computing.net/answers/unix/copy-files-with-pattern-from-a-file/6254.html