Unix OS
--
Questions
--
Followers
Top Experts
using the ls commnad on ***Solaris*** to get the YEAR, date, time of a file.
Hi,
"ls -lc" only return the modification time with the
month, day, and time,
for example: Dec 26 16:07.
But How do I get the year? like 2005 or 2006?
thanks.
"ls -lc" only return the modification time with the
month, day, and time,
for example: Dec 26 16:07.
But How do I get the year? like 2005 or 2006?
thanks.
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Solaris is like every other OS. Functionality varies by VERSION. You didn't specify the version of Solaris, so I'm reference Solaris 9.
The "-l" returns the year if it is more than six months old. In that event you'd see:
Dec 26 2005
Here's the reference from the man page:
-l Lists in long format, giving mode, ACL indication,
number of links, owner, group, size in bytes, and time
of last modification for each file (see above). If the
file is a special file, the size field instead con-
tains the major and minor device numbers. 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'. If the file is a sym-
bolic link, the filename is printed followed by "->"
and the path name of the referenced file.
It looks like POSIX locale can be used to affect the output, so that may be the approach you want to take.
The "-l" returns the year if it is more than six months old. In that event you'd see:
Dec 26 2005
Here's the reference from the man page:
-l Lists in long format, giving mode, ACL indication,
number of links, owner, group, size in bytes, and time
of last modification for each file (see above). If the
file is a special file, the size field instead con-
tains the major and minor device numbers. 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'. If the file is a sym-
bolic link, the filename is printed followed by "->"
and the path name of the referenced file.
It looks like POSIX locale can be used to affect the output, so that may be the approach you want to take.
what is the file is not more than 6 months old, but I still want to get the year?
Thanks
Thanks
Well, if you don't use POSIX locale, then I'd say you examine the characters following the Month and Day. If they contain a colon (:), then the data is indicative of a date within the past 6 months. If the current date is July thru December, then the year is the current Year. Otherwise...
Short Answer: I'm not aware of any "clean" way to do this. Unless POSIX locales offer some options.
Short Answer: I'm not aware of any "clean" way to do this. Unless POSIX locales offer some options.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
>modern Solaris has -E option
I am not sure what he considers "Modern" Solaris, but only Solaris 10 has the -E option.
To see if it works for you just use the command;
ls -E
The output is a little different than what you are use to, right after the file size is the date in the format yyyy-mm-dd and the time in the format hh:mm:ss
If you tell us what you are trying to do that you need the year, someone here may no of a tool or technique that will preform your task....
I am not sure what he considers "Modern" Solaris, but only Solaris 10 has the -E option.
To see if it works for you just use the command;
ls -E
The output is a little different than what you are use to, right after the file size is the date in the format yyyy-mm-dd and the time in the format hh:mm:ss
If you tell us what you are trying to do that you need the year, someone here may no of a tool or technique that will preform your task....
Unix OS
--
Questions
--
Followers
Top Experts
Unix is a multitasking, multi-user computer operating system originally developed in 1969 at Bell Labs. Today, it is a modern OS with many commercial flavors and licensees, including FreeBSD, Hewlett-Packard’s UX, IBM AIX and Apple Mac OS-X. Apart from its command-line interface, most UNIX variations support the standardized X Window System for GUIs, with the exception of the Mac OS, which uses a proprietary system.