How to see future file timestamps in Solaris
I know I’ve spoken about timestamps already, but I’d like to further expand the topic.
While there’s a great GNU stat command in Linux systems, there’s no such thing in Solaris by default, and so you usually depend on ls command with various options to look at file’s creation, modification or access time.
The standard /bin/ls command in Solaris doesn’t always show you the full timpestamp, usually if it’s about a time too far in the past or a bit into the future – so today I’m going to show you a trick to work around it and still confirm such timestamps for any file.
Standard ls command in Solaris doesn’t always show full timestamps
Here’s an example: BigBrother monitoring suite creates np_ files for internal tracking of times to send out email notifications. It deliberately alters the timestamps so that they’re set for a future date – that’s how it tracks the time elapsed between the event and the next notification about it.
However, not all of these np_ files are shown with their full timestamps, some just show the date, with no time:
solaris$ ls -l *myserver1* -rw-r--r-- 1 bbuser bbgroup 48 Jan 9 2009 [email protected]_myserver1.conn -rw-r--r-- 1 bbuser bbgroup 50 Jan 9 10:41 [email protected]_myserver1.cpu -rw-r--r-- 1 bbuser bbgroup 51 Jan 9 10:41 [email protected]_myserver1.disk -rw-r--r-- 1 bbuser bbgroup 53 Jan 9 10:36 [email protected]_myserver1.memory -rw-r--r-- 1 bbuser bbgroup 51 Jan 9 10:41 [email protected]_myserver1.msgs -rw-r--r-- 1 bbuser bbgroup 52 Jan 9 2009 [email protected]_myserver1.procs
If you remember, the default behaviour for ls is to show the modification time of each file. So in this example you can see that two files only have the date, and not the time of their modification timestamps shown. For other files, the full timestamp is present.
Before we continue, let’s confirm the current time on this Solaris server:
solaris$ date Fri Jan 9 10:44:06 GMT 2009
For the two files with only date shown, ls recognizes that the file can’t really have a future modification timestamp, and only shows the part is agrees with – the date which is valid (today).
What can we do? First, double-check other times – like the creation time of these files:
solaris$ ls -lc *myserver1* -rw-r--r-- 1 bbuser bbgroup 48 Jan 9 10:14 [email protected]_myserver1.conn -rw-r--r-- 1 bbuser bbgroup 50 Jan 9 09:56 [email protected]_myserver1.cpu -rw-r--r-- 1 bbuser bbgroup 51 Jan 9 09:56 [email protected]_myserver1.disk -rw-r--r-- 1 bbuser bbgroup 53 Jan 9 09:51 [email protected]_myserver1.memory -rw-r--r-- 1 bbuser bbgroup 51 Jan 9 09:56 [email protected]_myserver1.msgs -rw-r--r-- 1 bbuser bbgroup 52 Jan 9 10:31 [email protected]_myserver1.procs
All of them are showing correct full timestamps from some time in the past, so that’s okay.
How to show future timestamps in Solaris
And now comes the moment to reveal the little trick I was talking about. Even though the standard /bin/ls command won’t show you the future timestamps, you can still check them using the /usr/ucb/ls version of the ls command. The syntax is very similar, but you can also see the future timestamps:
solaris$ /usr/ucb/ls -al *myserver1* -rw-r--r-- 1 bbuser 48 Jan 9 10:59 [email protected]_myserver1.conn -rw-r--r-- 1 bbuser 50 Jan 9 10:41 [email protected]_myserver1.cpu -rw-r--r-- 1 bbuser 51 Jan 9 10:41 [email protected]_myserver1.disk -rw-r--r-- 1 bbuser 53 Jan 9 10:36 [email protected]_myserver1.memory -rw-r--r-- 1 bbuser 51 Jan 9 10:41 [email protected]_myserver1.msgs -rw-r--r-- 1 bbuser 52 Jan 9 11:16 [email protected]_myserver1.procs
Looking at them, you can see that BigBrother simply set the modification time for these files to be 45min into the future.
That’s it for today – hope you liked this trick!