Skip to content

Linux 常用命令(3):系统

ls

显示指定目录下的内容,列出工作目录所含的文件及子目录。

shell
ls [选项] [路径或文件]
选项说明
-a显示指定目录下的所有文件及子目录,包含隐藏文件(Linux 下将“.”开头的文件或者目录视为隐藏文档)
-l除文件名称外,同时将文件或者子目录的权限、使用者和大小等详细信息列出来
-S以文件大小排序

pwd

显示当前的工作目录

cd

改变当前工作目录

shell
cd [目录名]

date

显示或者修改系统时间与日期。

shell
date [选项] 显示时间格式(以 + 开头,后面接时间格式)
shell
root@a-server:~# date
Thu Jun 17 16:48:44 CST 2021
root@a-server:~# date '+%Y-%m-%d'
2021-06-17

passwd

设置用户密码

shell
passwd [用户名]

su

改变用户身份

shell
su [选项] [用户名]

普通用户成为超级用户:

shell
su -

clear

清除屏幕信息

shell
clear

man

显示指定命令的帮助信息

shell
man [命令名称]
shell
man ls

who

显示当前登录到系统的用户

shell
who [选项] [file]

输出格式一般如下:

shell
名称 [状态] 终端 时间 [活动] [进程标志] (主机名)
shell
root@a-server:~# who
root     pts/0        2021-06-17 16:16 (172.10.10.14)
root@a-server:~# who -a
           system boot  2021-05-13 14:19
LOGIN      tty1         2021-05-13 14:19              1273 id=tty1
           run-level 5  2021-05-13 14:19
root     - pts/0        2021-06-17 16:16   .          9856 (172.10.10.14)

w

显示登录到系统的用户信息

shell
w [选项] [用户]
shell
root@a-server:~# w
 17:00:32 up 35 days,  2:41,  1 user,  load average: 2.91, 2.95, 2.85
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    172.10.10.14     16:16    0.00s  0.04s  0.00s w

uname

显示操作系统相关信息

shell
uname [选项]
选项说明
-a显示操作系统全部信息
shell
root@a-server:~# uname
Linux
root@a-server:~# uname -a
Linux a-server 4.4.0-131-generic #157-Ubuntu SMP Thu Jul 12 15:51:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

uptime

输出当前系统时间、系统开机到现在的运行时间、目前有多少用户在线和系统平均负载等。

shell
uptime
shell
root@a-server:~# uptime
 17:04:19 up 35 days,  2:45,  1 user,  load average: 2.58, 2.82, 2.81

last

列出目前与过去登入系统的用户相关信息。

shell
last [选项] [-n 显示列数]
shell
root@a-server:~# last
root     pts/0        172.10.10.14     Thu Jun 17 16:16   still logged in
root     pts/0        172.10.10.14     Tue Jun 15 11:51 - 16:16 (2+04:24)

wtmp begins Tue Jun 15 11:51:31 2021

dmesg

显示开机信息

shell
dmesg [选项]

free

显示系统内存状态。

shell
free [选项] [-s (间隔秒数)]
选项说明
-b以字节为单位显示内存使用情况
-m以 MB 为单位显示内存使用情况
-K以 KB 为单位显示内存使用情况
-t显示内存总和行
shell
root@a-server:~# free
              total        used        free      shared  buff/cache   available
Mem:        8174824     4923816      203896       30080     3047112     2867596
Swap:        998396      998360          36
root@a-server:~# free -m
              total        used        free      shared  buff/cache   available
Mem:           7983        4808         199          29        2975        2800
Swap:           974         974           0

ps

显示系统进程在瞬间的运行动态。

shell
ps [选项]
选项说明
a显示所有用户的进程,包含每个程序的完整路径
-x显示所有系统程序,包含那些没有终端的程序
-u显示使用者的名称和起始时间
-f详细显示程序执行的路径群
-c只显示进程的名称,不显示进程的完整路径
-e将除内核进程以外的信息写到标准输出
shell
root@a-server:~# ps
  PID TTY          TIME CMD
 9856 pts/0    00:00:00 bash
10630 pts/0    00:00:00 su
10631 pts/0    00:00:00 bash
11187 pts/0    00:00:00 ps
root@a-server:~# ps a
  PID TTY      STAT   TIME COMMAND
 1273 tty1     Ss+    0:00 /sbin/agetty --noclear tty1 linux
 9856 pts/0    Ss     0:00 -bash
10630 pts/0    S      0:00 su -
10631 pts/0    S      0:00 -su
11188 pts/0    R+     0:00 ps a

top

系统处理器状态的实时监控,能够实时显示系统中各个进程的资源占用情况。

shell
top [选项]
shell
top - 18:07:30 up 35 days,  3:48,  1 user,  load average: 0.15, 0.37, 2.09
Tasks: 205 total,   1 running, 204 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.5 us,  0.2 sy,  0.1 ni, 99.1 id,  0.0 wa,  0.0 hi,  0.1 si,  0.0 st
KiB Mem :  8174824 total,   162416 free,  4928208 used,  3084200 buff/cache
KiB Swap:   998396 total,       32 free,   998364 used.  2862988 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  950 root      39  19 4781172 601684   8528 S   1.0  7.4 214:09.05 java
 1424 rabbitmq  20   0 2324744 138564   3912 S   1.0  1.7 255:35.37 beam.smp
 1788 es        20   0 6881160 1.208g  23788 S   1.0 15.5 554:16.31 java
 1222 mysql     20   0 3544128 1.058g   9820 S   0.7 13.6   1150:38 mysqld
 1058 root      20   0 1348724 180032   7776 S   0.3  2.2 169:59.84 node
 1081 root      20   0  678932  19416   3060 S   0.3  0.2  10:37.88 containerd
 1615 jenkins   20   0 5793428 1.253g   8408 S   0.3 16.1  27:19.52 java
    1 root      20   0   38008   4644   2928 S   0.0  0.1   0:16.41 systemd

Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.