Operating System - HP-UX
1827428 Members
3609 Online
109965 Solutions
New Discussion

How can I get the time in seconds from the command line.

 
Luis Montañés
Occasional Contributor

How can I get the time in seconds from the command line.

??Is the command date capable to do it?
5 REPLIES 5
Robin Wakefield
Honored Contributor

Re: How can I get the time in seconds from the command line.

Hi,

I'd use perl:

perl -e 'print time(),"\n"'

rgds, Robin
A. Clay Stephenson
Acclaimed Contributor

Re: How can I get the time in seconds from the command line.

This is about as easy as it gets:

NSECONDS=$(perl -e 'print scalar time')
echo "Epoch seconds = ${NSECONDS}"
If it ain't broke, I can fix that.
Ian Lochray
Respected Contributor

Re: How can I get the time in seconds from the command line.

Do you mean the number of seconds since midnight, th enumber of seconds this year or the number of seconds A.D.?
Chris Vail
Honored Contributor

Re: How can I get the time in seconds from the command line.

If you want to know how long it took the computer to do something, execute the comand with 'timex'.
Example: Try 'timex ioscan -fnC disk' for starters, and compare with 'timex ioscan -funC disk'. The first time (without the u argument to the ioscan) it took 16.64 seconds on one of my systems. With the u command, it took 0.18 seconds. The difference is that the -u argument read the disk configuration from memory, while the command without it actually caused the system to go out and see what disks it actually had.
We use timex here to check on how fast our backups are going.

Chris
Jose Mosquera
Honored Contributor

Re: How can I get the time in seconds from the command line.

Hi,

#HOUR=`date +%H`
#echo $HOUR
#MINUTES=`date +%M`
#echo $MINUTES
SECONDS=`date +%S`
#echo $SECONDS

-or once sintax -

#date +%H:%M:%S


Rgds.