How to check system uptime in Linux Ubuntu. Terminal command to check system uptime in Linux. Linux uptime command to find how long the Ubuntu system has been running. You can easily find the last time Linux system was rebooted / restarted and logged in.
Tuptime tool is a wonderful “System Administration Tool” to know for how long a Linux System has been running. Tuptime is a command line tool for reporting the historical and statistical running time of the system, keeping it between restarts.
The tuptime command line tool can:
- Count system startups
- Register first boot time (a.k.a. installation time)
- Count nicely and accidentally shutdowns
- Uptime and downtime percentage since first boot time
- Accumulated system uptime, downtime and total
- Largest, shortest and average uptime and downtime
- Current uptime
- Print formatted table or list with most of the previous values
- Register used kernel
Installing TupTime on Linux Systems
There are few prerequisites for the Tuptime tool:
- Python 2.7 or Python 3.X (Latest version recommended)
- Python modules (most included in python core by default): sys, os, optparse, sqlite3, datetime, locale, platform, subprocess, time
- In Debian: ‘python’ package >= 2.7
- In FreeBSD: ‘/usr/ports/lang/python’ and ‘/usr/ports/databases/py-sqlite3’
The Tuptime can be installed and run on Linux and FreeBSD OS. Please note that you must have root permission to run the following commands in Terminal. You can also use sudo permission for executing each command.
Run the following command to clone the git repository and install tuptime in Linux Systems:
# git clone https://github.com/rfrail3/tuptime.git
Once cloned, run the following commands to copy tuptime script to /usr/bin and set executable permission for the script:
$ cd tuptime/latest
$ sudo cp tuptime /usr/bin/tuptime
$ sudo chmod ugo+x /usr/bin/tuptime
Now it’s time to configure tuptime. To do this, either manually copy the cron file tuptime/latest/cron.d/tuptime to /etc/cron.d/tuptime directory and set executable permission for the script. You can also do it using CLI commands, run the following commands to do the same:
$ sudo cp tuptime/latest/cron.d/tuptime /etc/cron.d/tuptime
$ sudo chmod 644 /etc/cron.d/tuptime
Once installed, you can run and use the TupTime tool by running “tuptime” command. You can either run the “tuptime” command alone or use various command line parameters.
There are more than 15 CLI parameters / options that can be used with tuptime command.
Below is the list of CLI parameters:
General
-h, –help show this help message and exit
-c, –ckernel classify / order by kernel
Date format output
-d DATE_FORMAT, –date=DATE_FORMAT
-e, –end order by end state
-f FILE, –filedb=FILE
-e, –end order by end state
-f FILE, –filedb=FILE
Database file
-g, –graceful register a gracefully shutdown
-k, –kernel print kernel information
-l, –list enumerate system life as list
-o, –offtime order by offtime / downtime
-r, –reverse reverse order
-s, –seconds output time in seconds and epoch
-t, –table enumerate system life as table
-u, –uptime order by uptime
-v, –verbose verbose output
-V, –version show version
-x, –silent update values into db without output
-c, –ckernel
Order table or list by kernel name. Therefore, only works in conjunction with (-k) and (-t) or (-l) options.
Examples:
tuptime -ckl
tuptime -ckt
tuptime -t –ckernel
tuptime -l –ckernel
-d , –date Change the date format. By default it’s printed based on system locales. Allow values are:
%a Weekday as locale’s abbreviated name.
%A Weekday as locale’s full name.
%w Weekday as a decimal number, where 0 is Sunday and 6 is Saturday.
%d Day of the month as a zero-padded decimal number.
%b Month as locale’s abbreviated name.
%B Month as locale’s full name.
%m Month as a zero-padded decimal number.
%y Year without century as a zero-padded decimal number.
%Y Year with century as a decimal number.
%H Hour (24-hour clock) as a zero-padded decimal number.
%I Hour (12-hour clock) as a zero-padded decimal number.
%p Locale’s equivalent of either AM or PM.
%M Minute as a zero-padded decimal number.
%S Second as a zero-padded decimal number.
%f Microsecond as a decimal number, zero-padded on the left.
Examples:
tuptime -d ‘%X %x’ # (Default)
tuptime -d ‘%H:%M:%S %m-%d-%Y’ # British style
tuptime -d ‘%H:%M:%S %d-%b-%Y’ # Spanish style
-e, –end Order table or list by end status at power off. Therefore, only works in conjunction with (-t) or (-l) options.
Examples:
tuptime -te
tuptime -le
tuptime -t –end
tuptime -l –end
-f , –filedb Define an alternative database file. Default is located in ‘/var/lib/tuptime/tuptime.db’
Examples:
tuptime -f /var/lib/tuptime/tuptime.db # (Default)
tuptime -f /tmp/test1.db
tuptime –filedb /tmp/test2.db
-g, –graceful Register last time in the db as a graceful shutdown. This option is the way that tuptime have for know if is a good or a bad shutdown, like a hang of the system, for example. This is used in the init.d and systemd files at the shutdown process.
Examples:
tuptime -g
tuptime –graceful
-k, –kernel Add kernel information to the output.
Examples:
tuptime -k
tuptime -lk
tuptime –kernel
tuptime -t –kernel
-l, –list Enumerate as list each startup number, startup date, uptime, shutdown date, end status and offtime. Multiple order options can be combined together.
Examples:
tuptimoe -l
tuptimoe –list
-o, –offtime Order table or list by offtime / downtime. Therefore, only works in conjunction with (-t) or (-l) options.
Examples:
tuptime -to
tuptime -lo
tuptime -t –offtime
tuptime -l –offtime
-r, –reverse Reverse the order for table or list output. Therefore, only works in conjunction with any of (-t), (-l), (-e), (-o), (-u) and (-c) options.
Examples:
tuptime -tr
tuptime -lur
tuptime -teo –reverse
tuptime -l –reverse
-t, –table Enumerate as table each startup number, startup date, uptime, shutdown date, end status and downtime. Multiple order options can be combined together.
Examples:
tuptimoe -t
tuptimoe –table
-u, –uptime Order table or list by uptime. Therefore, only works in conjunction with (-t) or (-l) options.
Examples:
tuptime -tu
tuptime -lu
tuptime -t –uptime
tuptime -l –uptime
-v, –verbose Print information about the internals of tuptime. It’s good for debugging how it gets the variables.
Examples:
tuptime -v
tuptime –verbose
-V, –version Print version number and exit.
Examples:
tuptime -V
tuptime –version
-x, –silent Any output is printed. Only update values and save them into disk.
Examples:
tuptime -x
tuptime –silent
For any help, you can use help command.