Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Let me say in detail.
My script will calculate the system uptime in time ticks.
But,I want to display it as number of hours. So I want to change the output from time ticks to hours. How can i modify the output?
Yes, an example of the input and the required output would be useful. If for "timeticks" you mean the number of seconds after some epoch, you can use the date command specifying the input with the -d option and formatting the output at your pleasure:
Code:
date -d @1231492552
the number of seconds since epoch must be preceded by @ otherwise the date command is not able to interpret the input correctly. The problem arises if your timeticks refer to an epoch different than the unix epoch (01-01-1970 01:00) so that you have to do some calculation to correct the discrepancy.
Edit: sorry, posted before seeing the reply above.
you can convert the time ticks to seconds and then divide by 60 to get hours.
So the trick is to determine how many time ticks there are in a second and divide the time ticks by that value and then divide by 60 and you have it.
usually, ticks means C.P.U. clock ticks. Me too taught in the beginning like this only. But the O.P. is using date +%s which will give the seconds. He is calling the seconds as ticks which is not the general intention.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.