Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Year on ls -l

Status
Not open for further replies.

IMAUser

Technical User
May 28, 2003
121
CH

Can I get the year on a ls listing of a directory

-rw-r--r-- 1 owner grp 1033 Jun 27 14:05 batch.sh

is a usual entry, but if this file was created last year the entry looks like

-rw-r--r-- 1 owner grp 1033 Jun 27 2002 batch.sh

Can I always get the year, or somehow also have the year in the ls option.

Thanks
 
NO - and here's why
Column 8 is always either date or time and column 9 is always the filename. If this was to vary, then scripts that look for column 9 would get a date (not the name !) if it was over a year old.
-rw-rw-rw- 1 backup staff 341 05 Feb 13:16 mscstx10.mel.wed
-rw-r--r-- 1 backup staff 341 04 Feb 13:16 mscstx10.melbn.tue
-rw-rw-rw- 1 backup staff 665 31 Jan 13:16 mscstx10.mel.fri
-rw-rw-rw- 1 msmith cdev 8203 25 Sep 2002 VALUES
-rw-rw-rw- 1 backup staff 341 05 Aug 2002 mscstx10.mel

Dickie Bird (:)-)))
 
#!/bin/ksh

year=$(date +%Y)

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


vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
If you are using a GNU based ls you can use the
Code:
 --time-style
parm to force date/time to be displayed consistently. eg:
Code:
ls -alrt --time-style='+%Y.%d.%m %H:%M:%S'
Most commencial unices don't have a GNU ls by default.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top