In order to check since the last login (or boot time) of the system how many days and time have elapsed one may make use of the uptime or the w command. In this tutorial, we will stick to the uptime command.
Syntax: uptime
This is a BSD General Command and so works on Linux/Unix/macOS or Bash for Windows. This command was added to the BSD list in the year 1994 in BSD version 3.0
Let's see an example of this command.
$ uptime
0:30 up 18 days, 14:58, 2 users, load averages: 1.07 1.29 1.31
How to read the output of the uptime command?
As you can see in the above example there are multiple sections to the output you see of the command. Let's break them down
- 0:30 -> This is the time in HH:mm when the command was fired. The time on the system/server.
- up 18 days, 14:58 -> This show for how many days the system is up and running followed the hours and minutes.
- 2 users -> Next it shows number of users that are logged in to the system.
- load averages: 1.07 1.29 1.31 -> As the name suggests it is the load averages - you see three numbers here that represents 3 load averages in the last one, five and fifteen minutes respectively.
The best way to get more details about any shell command is by using the manual,
$ man uptime
UPTIME(1) BSD General Commands Manual UPTIME(1)
NAME
uptime -- show how long system has been running
SYNOPSIS
uptime
DESCRIPTION
The uptime utility displays the current time,
the length of time the system has been up,
the number of users, and the load average of the system
over the last 1, 5, and 15 minutes.
SEE ALSO
w(1)
HISTORY
The uptime command appeared in 3.0BSD.
BSD April 18, 1994 BSD
(END)
✏️ The above examples are based on macOS running Big Sur.
What are the optional parameters available with uptime command?
If you are using Linux OS - you would see that there are multiple options that you can make use of with the uptime command:
- -p, --pretty => This option will display the uptime in pretty format.
- -s, --since => This option will display system up since details.
- -V, --version => This option will display version information and exit.
Aslo you can make use of -h to display the help details,
$ uptime -h
Usage:
uptime [options]
Options:
-p, --pretty show uptime in pretty format
-h, --help display this help and exit
-s, --since system up since
-V, --version output version information and exit
For more details see uptime(1).
Let's see some examples:
1. Show uptime in pretty format
$ uptime -p
up 11 weeks, 22 days, 21 hours, 10 minute
2. system up since
$ uptime -s
2021-07-16 12:12:55
3. Output version information and exit
$ uptime -V
uptime from max-ag 2.1.11
Note if you try to use the command with options macOS you will get errors as below,
bash-3.2$ uptime -p
uptime: illegal option -- p
usage: uptime
bash-3.2$ uptime -s
uptime: illegal option -- s
usage: uptime
bash-3.2$ uptime -V
uptime: illegal option -- V
usage: uptime
Have Questions? Post them here!
- Command to know the Available Memory on Linux System
- How to install curl on Alpine Linux
- How to backup a file in Linux/Unix
- Install Java Runtime Environment (Oracle or open JRE) on Ubuntu
- What is the Default Admin user and Password for Jenkins
- How to tar.gz a directory or folder Command
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: bash: ipconfig: command not found on Linux
- Command to check Last Login or Reboot History of Users and TTYs
- Linux: Create a New User and Password and Login Example
- ls command to list only directories
- bash: cls: command not found
- How to exit from nano command
- Installing and using unzip Command to unzip a zip file using Terminal
- What does apt-get update command does?
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- How to remove or uninstall Java from Ubuntu using apt-get
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- Sort ls command by last modified date and time
- Create Nested Directories using mkdir Command
- How to Exit a File in Terminal (Bash/Zsh)
- Command to know the installed Debian version?
- How to connect to SSH port other than default 22
- How to save a file in Nano Editor and Exit
- Install OpenSSL on Linux/Ubuntu
- How to Add a horizontal line in Android Layout - Android
- Calculate days between dates using dateutils ddiff command - Linux
- Reading JSON file in Python with Examples - Python
- Error 404 Tomcat homepage http://localhost:8080/ not displayed - Tomcat
- 5+ Fibonacci number Series Java Program Examples [ 0 1 1 2 3 ..] - Java
- pip install see the list of all available versions of package - PIP
- Tomcat Manager Default Username and Password - Tomcat
- Open Terminal in Finder Current Location - MacOS