It’s Official: The 2019 Standard Deduction Is Getting Even Large
Unix

Number of seconds since midnight till now in unix

Image of Clock

Had a requirement to find out the number of seconds since midnight till now in unix.

Basically the requirment was more to this, it was to find the latest file created after midnight having specific pattern and to search certain pattern in it 😉 nice one right……

Anyway splitting the blog to provide you the code to find out the number of seconds past midnight and solution is as below command

Number of second past midnight till now

echo $(( ($(date “+%s”) – $(date -d ‘today 00:00:00’ “+%s”)) ))

Number of minutes past midnight till now

echo $(( ($(date “+%s”) – $(date -d ‘today 00:00:00’ “+%s”))/60 ))

 

Explanation :

$(date “+%s”) : Gives current seconds elapsed since January 1, 1970 (Unix epoch)

$(date -d ‘today 00:00:00’ “+%s”) : Gives seconds at midnight elapsed since January 1, 1970

$(( ($(date “+%s”) – $(date -d ‘today 00:00:00’ “+%s”)) )) : Difference of both seconds

$(( ($(date “+%s”) – $(date -d ‘today 00:00:00’ “+%s”))/60 )) : Difference of both seconds and divide by 60 to get minutes

About author

Love coding, crazy about logic, like solution architecting and solving problems. Thirsty for knowledge, challenges & most importantly innovation. One of the passionate brain behind SpryOX
Related posts
OSUnix

df says disk is full, but it is not

OSUnix

Removing Older files in Unix

Unix

Find latest file created having specific pattern and to search certain pattern

Unix

Remove duplicate lines from file using awk

Sign up for our Newsletter and
stay informed

Leave a Reply

Your email address will not be published. Required fields are marked *