菜鸟们，通过这几个例子，包你学会 uptime 命令的用法
uptime 启动
![](/data/attachment/album/201802/20/143517d5vkxnsiziu5lqbu.jpg)


Linux 小白，若对系统管理有兴趣，或想成为资深用户，就需要对命令行有扎实的功底。你需要知道很多命令，其中一个就是 `uptime`。文本我们会通过一些容易理解的案例来讲解一下这个命令的基本用法。


再开始前有必要说一下，文中的所有案例都在 Ubuntu 16.04 上测试过了。


### Linux uptime 命令


望名生义，`uptime` 命令告诉你系统<ruby> 启动 <rt>  up </rt></ruby>了（运行了）多长时间。这是语法：



```
uptime [options]

```

这个工具的 man 页是这么说的：



> 
> `uptime`会在一行中显示下列信息：当前时间、系统运行了多久时间、当前登录的用户有多少，以及前 1、5 和 15 分钟系统的平均负载。
> 
> 
> 


下面这些问答形式的案例应该会让你对 `uptime` 命令有更好的了解。


### Q1、如何使用 uptime 命令


`uptime` 的基础用法很简单 —— 只需要输入命令名称然后按下回车就行。



```
uptime

```

这是输出：


[![How to use the uptime command](/data/attachment/album/201802/20/143526ahnt5s5bhp7n75z3.png)](https://www.howtoforge.com/images/usage_of_pfsense_to_block_dos_attack_/big/uptime-basic-usage1.png)


这里，第一项是当前时间，`up` 表示系统正在运行，`5:53` 是系统启动的总时间，最后是系统的<ruby> 负载 <rt>  load </rt></ruby>信息。若你想深入了解，这里是 uptime man 页中关于最后一项信息的说明：



> 
> 系统负载是处于<ruby> 可运行 <rt>  runnable </rt></ruby>或<ruby> 不可中断 <rt>  uninterruptable </rt></ruby>状态的进程的平均数。可运行状态的进程要么正在使用 CPU 要么在等待使用 CPU。 不可中断状态的进程则正在等待某些 I/O 访问，例如等待磁盘 IO。
> 
> 
> 有三个时间间隔的平均值。负载均值的意义根据系统中 CPU 的数量不同而不同，负载为 1 对于一个只有单 CPU 的系统来说意味着负载满了，而对于一个拥有 4 CPU 的系统来说则意味着 75% 的时间里都是空闲的。
> 
> 
> 


### Q2、如何以更人性化的格式现实时间


若你只想知道系统运行了多长时间，而且希望以更人性化的格式来显示，那么可以使用 `-p` 项。



```
uptime -p

```

这是输出：


[![make the tool show up time in pretty format](/data/attachment/album/201802/20/143528r94ojuekjy5uyejm.png)](https://www.howtoforge.com/images/usage_of_pfsense_to_block_dos_attack_/big/uptime-p-option.png)


### Q3、如何让 uptime 显示系统启动的日期/时间


你也可以指定 `uptme` 显示系统开始运行的时间和日期。方法是使用 `-s` 命令项。



```
uptime -s

```

这是输出：


[![make uptime display date/time since when system is up](/data/attachment/album/201802/20/143529h21w9yi51bcziwie.png)](https://www.howtoforge.com/images/usage_of_pfsense_to_block_dos_attack_/big/uptime-s.png)


### Q4、如何获取版本信息和帮助信息


`-V` 获取版本信息，`-h` 获取帮助信息。



```
uptime -V

uptime -h

```

[![How to get version information and help](/data/attachment/album/201802/20/143531r8bxo18fobfwk65d.png)](https://www.howtoforge.com/images/usage_of_pfsense_to_block_dos_attack_/big/uptime-v-h.png)


### 结论


你可以看到，uptime 命令很容易理解也很容易使用。它没有提供很多的功能（命令选项也很少）。这里已经覆盖了它的所有功能了。因此只需要练习一下这些选项你就能在日常工作中使用它了。如果需要的话，你也可以查看它的 [man 页](https://linux.die.net/man/1/uptime)。




---


via: <https://www.howtoforge.com/linux-uptime-command/>


作者：[Himanshu Arora](https://www.howtoforge.com) 译者：[lujun9972](https://github.com/lujun9972) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
# Linux uptime Command Explained for Beginners with Examples

If you are a Linux newbie, and have interest in system administration, or you want to become a power user, then you need to have a solid knowledge of the command line. There are several commands that you should know about, and one of them is **uptime**. In this article, we will discuss the basics of this command using some easy to understand examples.

But before that, it's worth mentioning that all examples used in this tutorial have been tested on an Ubuntu 18.04 LTS machine.

## Linux uptime command

As the name suggests, the uptime command gives you the time for which the system has been up (or running). Here's its syntax:

uptime [options]

And here's is the way the tool's man page explains it:

uptime gives a one line display of the following information. The current time, how long the system

has been running, how many users are currently logged on, and the system load averages for the past

1, 5, and 15 minutes.

The following Q&A-styled examples should give you a better idea on how the uptime command works.

## Q1. How to use the uptime command

Uptime's basic usage is very easy - just write the command's name and press enter.

uptime

Here's the kind of output the tool produces:

So the first entry is the current time, then 'up' shows the system is running, 5:53 is the total time for which the system has been up, and then finally are the system load averages. Just in case you want to know more, here's what the uptime man page says about the last entry:

System load averages is the average number of processes that are either in a runnable or

uninterruptable state. A process in a runnable state is either using the CPU or waiting to use the

CPU. A process in uninterruptable state is waiting for some I/O access, eg waiting for disk.

The averages are taken over the three time intervals. Load averages are not normalized for the

number of CPUs in a system, so a load average of 1 means a single CPU system is loaded all the

time while on a 4 CPU system it means it was idle 75% of the time.

## Q2. How to make the tool show up time in pretty format

In case you just want to know the time for which the system has been up, and that too in a more human-readable format, use the **-p** command line option.

uptime -p

Here's the output this command produced in our case:

## Q3. How to make uptime display date/time since when the system is up

You can also make uptime specifically display the time/date since when the system has been running. This can be done using the **-s** command line option.

uptime -s

Here's the output the command produced in our case:

## Q4. How to get version information and help in general

Use the -V option to get version information, and -h for general help.

uptime -V

uptime -h

## Conclusion

As you'd have observed, the uptime command is easy to understand and use. It doesn't offer many features (or command line options). What all it offers have been discussed here. So just practice these options and you should be ready to use uptime in your day-to-day work. Just in case you require, here's the tool's [man page](https://linux.die.net/man/1/uptime).