You can use the following tools to see how long system has been running on a Linux or Unix-like system:
- uptime : Tell how long the server has been running.
- last command : Show the reboot and shutdown time.
- tuptime : Report the historical and statistical running time of system, keeping it between restarts. Like uptime command but with more interesting output.
- w command : How do you find the uptime of a Linux server?
Finding out the system last reboot time and date
You can use the following commands to get the last reboot and shutdown time and date on a Linux operating system (also works on OSX/Unix-like system):
## Just show system reboot and shutdown date and time ### who -b last reboot last shutdown ## Uptime info ## uptime cat /proc/uptime awk '{ print "up " $1 /60 " minutes"}' /proc/uptime w
Sample outputs:
Fig.01: Various Linux commands in action to find out the server uptime
Say hello to tuptime – Linux See Historical and Statistical Uptime of System
The tuptime command line tool can report the following information on a Linux and FreeBSD based system:
- Count system startups
- Register first boot time (a.k.a. installation time)
- Count nicely and accidentally shutdowns
- Average uptime and downtime
- Current uptime
- Uptime and downtime rate since first boot time
- Accumulated system uptime, downtime and total
- Report each startup, uptime, shutdown and downtime
Installation
Type the following command to clone a git repo on a Linux operating system:
$ cd /tmp
$ git clone https://github.com/rfrail3/tuptime.git
$ ls
$ cd tuptime
$ ls
Sample outputs:
Fig.02: Cloning a git repo
$ sudo tuptime-install.sh
How to do a manual installation
Copy the “tuptime” file located under “latest/” directory to “/usr/bin/” using cp command and make it executable using the chmod command:
sudo cp -v /tmp/tuptime/src/tuptime /usr/bin/tuptime
sudo chmod ugo+x /usr/bin/tuptime
Make sure you have Python version 3.x installed and working correctly:
python3 --version
Sample outputs:
Python 3.7.3
Package installation for Linux and FreeBSD
Debian and Ubuntu Linux use, run apt command/apt-get command:
sudo apt update
sudo apt install tuptime
Arch Linux user run pacman command:
sudo pacman -S pkgfile
A note about FreeBSD users
FreeBSD Unix users try the pkg command to install the same:
sudo pkg install tuptime
FreeBSD installation in action
cd /usr/ports/sysutils/tuptime/ && make install clean
tuptime requires execution at startup and shutdown on rc.d on FreeBSD, so add to /etc/rc.conf:
tuptime_enable="YES"
Finally, tuptime requires a scheduled execution on cron, therefore run crontab -e:
# crontab -e
Append the following line :
*/5 * * * * root /usr/local/bin/tuptime -x > /dev/null
Save and close the file. Start the service on FreeBSD:
# service tuptime start
Run it
Simply type the following command:
$ sudo tuptime
Sample outputs:
Fig.03: tuptime in action
$ sudo tuptime System startups: 2 since 03:52:16 PM 08/21/2015 System shutdowns: 1 ok - 0 bad Average uptime: 7 days, 16 hours, 48 minutes and 3 seconds Average downtime: 2 hours, 30 minutes and 5 seconds Current uptime: 5 minutes and 28 seconds since 06:23:06 AM 09/06/2015 Uptime rate: 98.66 % Downtime rate: 1.34 % System uptime: 15 days, 9 hours, 36 minutes and 7 seconds System downtime: 5 hours, 0 minutes and 11 seconds System life: 15 days, 14 hours, 36 minutes and 18 seconds
You can change date and time format as follows:
$ sudo tuptime -d '%H:%M:%S %m-%d-%Y'
Sample outputs:
System startups: 1 since 15:52:16 08-21-2015 System shutdowns: 0 ok - 0 bad Average uptime: 15 days, 9 hours, 21 minutes and 19 seconds Average downtime: 0 seconds Current uptime: 15 days, 9 hours, 21 minutes and 19 seconds since 15:52:16 08-21-2015 Uptime rate: 100.0 % Downtime rate: 0.0 % System uptime: 15 days, 9 hours, 21 minutes and 19 seconds System downtime: 0 seconds System life: 15 days, 9 hours, 21 minutes and 19 seconds
Enumerate each startup, uptime, shutdown and downtime:
$ sudo tuptime -e
Sample outputs:
Startup: 1 at 03:52:16 PM 08/21/2015 Uptime: 15 days, 9 hours, 22 minutes and 33 seconds System startups: 1 since 03:52:16 PM 08/21/2015 System shutdowns: 0 ok - 0 bad Average uptime: 15 days, 9 hours, 22 minutes and 33 seconds Average downtime: 0 seconds Current uptime: 15 days, 9 hours, 22 minutes and 33 seconds since 03:52:16 PM 08/21/2015 Uptime rate: 100.0 % Downtime rate: 0.0 % System uptime: 15 days, 9 hours, 22 minutes and 33 seconds System downtime: 0 seconds System life: 15 days, 9 hours, 22 minutes and 33 seconds
Conclusion
The uptime command show how long system has been up, and w command shows who is logged in and what they are doing. However, tuptime tool is an exciting tool to report the historical and statistical real time of the system, keeping it between restarts. It is just like uptime command but with more appealing output.
- Linux last Reboot Time and Date Find Out Command
- Linux / UNIX: Getting information about reboots and shutdowns
- Linux / Unix: last Command Examples
- tuptime project home page
- Report the historical and statistical running time of Linux system
- How to records statistics about a Linux machine's uptime
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 3 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
There’s absolutely no reason to run it as root, or with sudo. I simply made /var/lib/tuptime writable by my local, non-root user, and tuptime runs just fine.
Oh, yeah, if you run Arch, in the install script `python –version…` returns 3.4 currently, you’ll want to change that to `python2 –version`.
Actually in Debian it runs as a unprivileged user with python3. The table output is very helpfull.
The “tuptime” output has been upgraded on last releases and, also, it can be installed via Debian repo with “apt install tuptime”, it is an easy way than the repo clone and the manual steps.
It would be nice to have this article updated to match the current status.