brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: uptime -p prints how long a machine has been running in words

Linux
~/tips/tip-linux-uptime-p-pretty-format

uptime -p

Shows the system uptime as readable text, such as weeks, days and hours, instead of the classic load line.

The plain uptime output is a crowded line with the time, user count and three load averages. When I only want to know how long the machine has been up, there is a simpler form.

uptime -p
uptime -s

-p is short for --pretty and prints something like up 2 weeks, 3 days, 4 hours, 5 minutes. The option -s prints the date and time the system came up, which is handy when you want to know which night the reboot happened.

It is a nice one for a login message or a small status script. A line like this in a shell script is easy to read for a person:

echo "This server has been $(uptime -p)"

That prints the sentence with the pretty uptime at the end.

A long uptime is not something to brag about on a server. It can also mean that kernel updates are waiting for a reboot, so I look at it together with the update status. A short one after you did not reboot anything is worth a look in the logs.

The caveat is that these options belong to the procps-ng version of uptime, the one on most mainstream Linux distributions. Minimal systems, containers with a different implementation and other Unix-like systems may reject -p. In a container, remember that it may report the uptime of the host or of the container, depending on the version and on the option -c in newer releases, so read the man page for your version before trusting it.

Further reading: uptime(1) manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link