Linux系统命令从入门到完全忘记(三)

1,773次阅读
没有评论

Linux系统命令从入门到完全忘记(三)

有关磁盘空间的命令

mount

概要: 挂载文件系统,mount卸载挂载的文件系统

语法格式: mount [参数] [设备] [目录]

参数:

参数 概述
-a 挂载/etc/fstab里面的所有文件系统
-l 显示已挂载的文件系统列表
-r 将文件系统挂载为只读模式
-t 指定文件系统类型
-V 显示软件版本

使用示例:

  • 挂载当前系统的光驱到/mnt目录下
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
<span class="line">[root@ansheng ~]<span class="comment"># ls /mnt/</span></span>
<span class="line">[root@ansheng ~]<span class="comment"># mount /dev/sr0 /mnt/</span></span>
<span class="line">mount: block device /dev/sr0 is write-protected, mounting <span class="built_in">read</span>-only</span>
<span class="line">[root@ansheng ~]<span class="comment"># ls /mnt</span></span>
<span class="line">CentOS_BuildTag  isolinux                  RPM-GPG-KEY-CentOS-Debug-6</span>
<span class="line">EFI              Packages                  RPM-GPG-KEY-CentOS-Security-6</span>
<span class="line">EULA             RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Testing-6</span>
<span class="line">GPL              repodata                  TRANS.TBL</span>
<span class="line">images           RPM-GPG-KEY-CentOS-6</span>

umount

概要: 卸载以及挂载的文件系统

语法格式: umount 设备

使用示例:

  • 取消以及挂载的文件系统/dev/sda1
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
10
<span class="line">[root@ansheng ~]<span class="comment"># df -h</span></span>
<span class="line">Filesystem      Size  Used Avail Use% Mounted on</span>
<span class="line">/dev/sda3        19G  1.5G   17G   8% /</span>
<span class="line">tmpfs           491M     0  491M   0% /dev/shm</span>
<span class="line">/dev/sda1       190M   27M  153M  16% /boot</span>
<span class="line">[root@ansheng ~]<span class="comment"># umount /dev/sda1</span></span>
<span class="line">[root@ansheng ~]<span class="comment"># df -h</span></span>
<span class="line">Filesystem      Size  Used Avail Use% Mounted on</span>
<span class="line">/dev/sda3        19G  1.5G   17G   8% /</span>
<span class="line">tmpfs           491M     0  491M   0% /dev/shm</span>

df

概要: 查看文件系统磁盘使用情况

语法格式: df [参数]

参数:

参数 概述
-a 显示所有文件系统信息
-h 以M为单位显示
-i 显示Inode节点号

使用示例:

  • 显示当前文件系统使用信息,以M为单位显示,并且显示Inode节点
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">[root@ansheng /]<span class="comment"># df -hi</span></span>
<span class="line">Filesystem     Inodes IUsed IFree IUse% Mounted on</span>
<span class="line">/dev/sda3        1.3M   56K  1.2M    5% /</span>
<span class="line">tmpfs            123K     1  123K    1% /dev/shm</span>
<span class="line">/dev/sda1         50K    38   50K    1% /boot</span>

du

概要: 统计目录(或文件)所占磁盘空间的大小

语法格式: du [参数]

参数:

参数 概述
-h 显示单位
-m 以M为单位显示

使用示例:

  • 显示当前目录磁盘使用情况
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
<span class="line">[root@ansheng boot]<span class="comment"># pwd</span></span>
<span class="line">/boot</span>
<span class="line">[root@ansheng boot]<span class="comment"># du -h</span></span>
<span class="line">251K	./efi/EFI/redhat</span>
<span class="line">253K	./efi/EFI</span>
<span class="line">255K	./efi</span>
<span class="line">276K	./grub</span>
<span class="line">13K	./lost+found</span>
<span class="line">26M	.</span>

fdisk

概要: fdisk命令用于观察硬盘实体使用情况,也可对硬盘分区。

语法格式: fdisk [选项] [参数]

参数:

参数 说明
-b<分区大小> 指定每个分区的大小
-l 列出指定的外围设备的分区表状况
-u 搭配”-l”参数列表,会用分区数目取代柱面数目,来表示每个分区的起始地址

使用示例:

  • 查看当前系统分区信息
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
10
11
12
13
14
15
<span class="line">[root@ansheng ~]<span class="comment"># fdisk -l</span></span>

<span class="line">Disk /dev/sda: 21.5 GB, 21474836480 bytes</span>
<span class="line">255 heads, 63 sectors/track, 2610 cylinders</span>
<span class="line">Units = cylinders of 16065 * 512 = 8225280 bytes</span>
<span class="line">Sector size (logical/physical): 512 bytes / 512 bytes</span>
<span class="line">I/O size (minimum/optimal): 512 bytes / 512 bytes</span>
<span class="line">Disk identifier: 0x0004743c</span>

<span class="line">   Device Boot      Start         End      Blocks   Id  System</span>
<span class="line">/dev/sda1   *           1          26      204800   83  Linux</span>
<span class="line">Partition 1 does not end on cylinder boundary.</span>
<span class="line">/dev/sda2              26         157     1048576   82  Linux swap / Solaris</span>
<span class="line">Partition 2 does not end on cylinder boundary.</span>
<span class="line">/dev/sda3             157        2611    19717120   83  Linux</span>

dd

概要: dd命令用于复制文件并对原文件的内容进行转换和格式化处理。

语法格式: dd [OPERAND]… dd OPTION

参数:

参数 说明
bs=<字节数> 将ibs(输入)与欧巴桑(输出)设成指定的字节数
cbs=<字节数> 转换时,每次只转换指定的字节数
conv=<关键字> 指定文件转换的方式
count=<区块数> 仅读取指定的区块数
ibs=<字节数> 每次读取的字节数
obs=<字节数> 每次输出的字节数
of=<文件> 输出到文件
seek=<区块数> 一开始输出时,跳过指定的区块数
skip=<区块数> 一开始读取时,跳过指定的区块数

使用示例:

  • 创建一个大小为1G的sun.txt文件
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">[root@ansheng ~]<span class="comment"># dd if=/dev/zero of=sun.txt bs=1G count=1</span></span>
<span class="line">1+0 records <span class="keyword">in</span></span>
<span class="line">1+0 records out</span>
<span class="line">1073741824 bytes (1.1 GB) copied, 8.83111 s, 122 MB/s</span>
  • if 代表输入文件。如果不指定if,默认就会从stdin中读取输入
  • of 代表输出文件。如果不指定of,默认就会将stdout作为默认输出
  • bs 代表字节为单位的块大小
  • count 代表被复制的块数。
  • /dev/zero 是一个字符设备,会不断返回0值字节(\0)

查看系统信息

free

概要: 查看内存使用状态

语法格式: free [参数]

参数:

参数 概述
-m 以MB为单位显示

使用示例:

  • 显示当前内存使用信息
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">[root@ansheng ~]<span class="comment"># free -m</span></span>
<span class="line">             total       used       free     shared    buffers     cached</span>
<span class="line">Mem:           980        167        813          0         28         43</span>
<span class="line">-/+ buffers/cache:         95        885</span>
<span class="line">Swap:          511          0        511</span>

vmstat

概要: 用来显示虚拟内存的信息,对操作系统的虚拟内存、进程、CPU活动进行监控。

语法格式: vmstat [-a] [-n] [-S unit] [delay [ count]] vmstat [-s] [-n] [-S unit] vmstat [-m] [-n] [delay [ count]] vmstat [-d] [-n] [delay [ count]] vmstat [-p disk partition] [-n] [delay [ count]] vmstat [-f] vmstat [-V]

参数:

参数 说明
-a 显示活跃和非活跃内存
-f 显示从系统启动至今的fork数量
-m 显示slabinfo
-n 只在开始时显示一次各字段名称
-s 显示内存相关统计信息及多种系统活动数量
delay 刷新时间间隔。如果不指定,只显示一条结果
count 刷新次数。如果不指定刷新次数,但指定了刷新时间间隔,这时刷新次数为无穷
-d 显示磁盘相关统计信息
-p 显示指定磁盘分区统计信息
-S 使用指定单位显示。参数有 k 、K 、m 、M ,分别代表1000、1024、1000000、1048576字节(byte)。默认单位为K(1024 bytes)

使用示例:

  • 显示虚拟内存使用情况
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
<span class="line">[root@ansheng ~]<span class="comment"># vmstat 5 6</span></span>
<span class="line">procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----</span>
<span class="line"> r  b   swpd   free   buff  cache   si   so    bi    bo   <span class="keyword">in</span>   cs us sy id wa st</span>
<span class="line"> 0  0      0 1797468  11652  29852    0    0    20     1   12   14  0  0 100  0  0</span>
<span class="line"> 0  0      0 1797420  11652  29880    0    0     0     0   10   11  0  0 100  0  0</span>
<span class="line"> 1  0      0 1797420  11652  29880    0    0     0     0    7    9  0  0 100  0  0</span>
<span class="line"> 0  0      0 1797420  11652  29880    0    0     0     0    7   10  0  0 100  0  0</span>
<span class="line"> 0  0      0 1797420  11652  29880    0    0     0     0    8   10  0  0 100  0  0</span>
<span class="line"> 0  0      0 1797420  11652  29880    0    0     0     0    6   10  0  0 100  0  0</span>

字段说明:

Procs(进程)

字段 说明
r 运行队列中进程数量
b 等待IO的进程数量

Memory(内存)

字段 说明
swpd 使用虚拟内存大小
free 可用内存大小
buff 用作缓冲的内存大小
cache 用作缓存的内存大小

Swap

字段 说明
si 每秒从交换区写到内存的大小
so 每秒写入交换区的内存大小
IO 现在的Linux版本块的大小为1024bytes
bi 每秒读取的块数
bo 每秒写入的块数

系统

字段 说明
in 每秒中断数,包括时钟中断
cs 每秒上下文切换数

CPU(以百分比表示)

字段 说明
us 用户进程执行时间(user time)
sy 系统进程执行时间(system time)
id 空闲时间(包括IO等待时间),中央处理器的空闲时间 。以百分比表示
wa 等待IO时间
  • 查看内存使用的详细信息
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<span class="line">[root@ansheng ~]<span class="comment"># vmstat -s</span></span>
<span class="line">      1906904  total memory</span>
<span class="line">       109452  used memory</span>
<span class="line">        16112  active memory</span>
<span class="line">        30372  inactive memory</span>
<span class="line">      1797452  free memory</span>
<span class="line">        11660  buffer memory</span>
<span class="line">        29884  swap cache</span>
<span class="line">      1048572  total swap</span>
<span class="line">            0  used swap</span>
<span class="line">      1048572  free swap</span>
<span class="line">           79 non-nice user cpu ticks</span>
<span class="line">            0 nice user cpu ticks</span>
<span class="line">          475 system cpu ticks</span>
<span class="line">       302272 idle cpu ticks</span>
<span class="line">           70 IO-wait cpu ticks</span>
<span class="line">            1 IRQ cpu ticks</span>
<span class="line">            3 softirq cpu ticks</span>
<span class="line">            0 stolen cpu ticks</span>
<span class="line">        46598 pages paged <span class="keyword">in</span></span>
<span class="line">         1549 pages paged out</span>
<span class="line">            0 pages swapped <span class="keyword">in</span></span>
<span class="line">            0 pages swapped out</span>
<span class="line">        29862 interrupts</span>
<span class="line">        35402 CPU context switches</span>
<span class="line">   1461585872 boot time</span>
<span class="line">         1161 forks</span>
  • 查看磁盘的读/写
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<span class="line">[root@ansheng ~]<span class="comment"># vmstat -d</span></span>
<span class="line">disk- ------------reads------------ ------------writes----------- -----IO------</span>
<span class="line">       total merged sectors      ms  total merged sectors      ms    cur    sec</span>
<span class="line">ram0       0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram1       0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram2       0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram3       0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram4       0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram5       0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram6       0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram7       0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram8       0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram9       0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram10      0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram11      0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram12      0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram13      0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram14      0      0       0       0      0      0       0       0      0      0</span>
<span class="line">ram15      0      0       0       0      0      0       0       0      0      0</span>
<span class="line">loop0      0      0       0       0      0      0       0       0      0      0</span>
<span class="line">loop1      0      0       0       0      0      0       0       0      0      0</span>
<span class="line">loop2      0      0       0       0      0      0       0       0      0      0</span>
<span class="line">loop3      0      0       0       0      0      0       0       0      0      0</span>
<span class="line">loop4      0      0       0       0      0      0       0       0      0      0</span>
<span class="line">loop5      0      0       0       0      0      0       0       0      0      0</span>
<span class="line">loop6      0      0       0       0      0      0       0       0      0      0</span>
<span class="line">loop7      0      0       0       0      0      0       0       0      0      0</span>
<span class="line">sda     2412   2339   90132    1414    207    200    3250     429      0      1</span>

这些信息主要来自于/proc/diskstats

  • 查看/dev/sda1磁盘的读/写
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
6
7
8
<span class="line">[root@ansheng ~]<span class="comment"># df</span></span>
<span class="line">Filesystem     1K-blocks    Used Available Use% Mounted on</span>
<span class="line">/dev/sda3       19276064 3710860  14579348  21% /</span>
<span class="line">tmpfs             953452       0    953452   0% /dev/shm</span>
<span class="line">/dev/sda1         194241   74429    109572  41% /boot</span>
<span class="line">[root@ansheng ~]<span class="comment"># vmstat -p /dev/sda1</span></span>
<span class="line">sda1          reads   <span class="built_in">read</span> sectors  writes    requested writes</span>
<span class="line">                 497       3986          3         18</span>

说明:

这些信息主要来自于/proc/diskstats。

参数 说明
reads 来自于这个分区的读的次数
read sectors 来自于这个分区的读扇区的次数
writes 来自于这个分区的写的次数
requested writes 来自于这个分区的写请求次数

mpstat

概要: mpstat是MultiProcessor Statistics的缩写,是实时系统监控工具,其报告与CPU的一些统计信息,这些信息存放在/proc/stat文件中。

语法格式: mpstat [-P {|ALL}] [internal [count]]

参数:

|参数|说明| |-P {|ALL}|表示监控哪个CPU, cpu在[0,cpu个数-1]中取值| |internal|相邻的两次采样的间隔时间| |count|采样的次数,count只能和delay一起使用|

使用示例:

  • 查看多核CPU核心的当前运行状况信息, 每2秒更新一次
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<span class="line">[root@ansheng ~]<span class="comment"># mpstat  -P ALL 2</span></span>
<span class="line">Linux 2.6.32-573.22.1.el6.x86_64 (ansheng)      04/25/2016      _x86_64_        (2 CPU)</span>

<span class="line">08:41:21 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle</span>
<span class="line">08:41:23 PM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00</span>
<span class="line">08:41:23 PM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00</span>
<span class="line">08:41:23 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00</span>

<span class="line">08:41:23 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle</span>
<span class="line">08:41:25 PM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00</span>
<span class="line">08:41:25 PM    0    0.00    0.00    0.50    0.00    0.00    0.00    0.00    0.00   99.50</span>
<span class="line">08:41:25 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00</span>

<span class="line">08:41:25 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle</span>
<span class="line">08:41:27 PM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00</span>
<span class="line">08:41:27 PM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00</span>
<span class="line">08:41:27 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00</span>

<span class="line">08:41:27 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle</span>
<span class="line">08:41:29 PM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00</span>
<span class="line">08:41:29 PM    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00</span>
<span class="line">08:41:29 PM    1    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00</span>
<span class="line">......</span>

字段含义

字段 说明
%user 在internal时间段里,用户态的CPU时间(%),不包含nice值为负进程 (usr/total)*100
%nice 在internal时间段里,nice值为负进程的CPU时间(%) (nice/total)*100
%sys 在internal时间段里,内核时间(%) (system/total)*100
%iowait 在internal时间段里,硬盘IO等待时间(%) (iowait/total)*100
%irq 在internal时间段里,硬中断时间(%) (irq/total)*100
%soft 在internal时间段里,软中断时间(%) (softirq/total)*100
%idle 在internal时间段里,CPU除去等待磁盘IO操作外的因为任何原因而空闲的时间闲置时间(%) (idle/total)*100

iostat

概要: 通过iostat方便查看CPU、网卡、tty设备、磁盘、CD-ROM 等等设备的活动情况, 负载信息。

语法格式: iostat[参数][时间][次数]

参数:

参数 说明
-C 显示CPU使用情况
-d 显示磁盘使用情况
-k 以 KB 为单位显示
-m 以 M 为单位显示
-N 显示磁盘阵列(LVM) 信息
-n 显示NFS 使用情况
-p[磁盘] 显示磁盘和分区的情况
-t 显示终端和CPU的信息
-x 显示详细信息
-V 显示版本信息

使用示例:

  • 显示所有设备负载情况
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
6
7
8
<span class="line">[root@ansheng ~]<span class="comment"># iostat</span></span>
<span class="line">Linux 2.6.32-573.22.1.el6.x86_64 (ansheng)      04/25/2016      _x86_64_        (2 CPU)</span>

<span class="line">avg-cpu:  %user   %nice %system %iowait  %steal   %idle</span>
<span class="line">           0.02    0.00    0.11    0.02    0.00   99.85</span>

<span class="line">Device:            tps   Blk_<span class="built_in">read</span>/s   Blk_wrtn/s   Blk_<span class="built_in">read</span>   Blk_wrtn</span>
<span class="line">sda               1.12        37.87         1.56      90588       3738</span>

属性值说明

cpu属性值说明

说明
%user CPU处在用户模式下的时间百分比
%nice CPU处在带NICE值的用户模式下的时间百分比
%system CPU处在系统模式下的时间百分比
%iowait CPU等待输入输出完成时间的百分比
%steal 管理程序维护另一个虚拟处理器时,虚拟CPU的无意识等待时间百分比
%idle CPU空闲时间百分比

备注:如果%iowait的值过高,表示硬盘存在I/O瓶颈,%idle值高,表示CPU较空闲,如果%idle值高但系统响应慢时,有可能是CPU等待分配内存,此时应加大内存容量。%idle值如果持续低于10,那么系统的CPU处理能力相对较低,表明系统中最需要解决的资源是CPU。

disk属性值说明:

说明
rrqm/s 每秒进行 merge 的读操作数目。即 rmerge/s
wrqm/s 每秒进行 merge 的写操作数目。即 wmerge/s
r/s 每秒完成的读 I/O 设备次数。即 rio/s
w/s 每秒完成的写 I/O 设备次数。即 wio/s
rsec/s 每秒读扇区数。即 rsect/s
wsec/s 每秒写扇区数。即 wsect/s
rkB/s 每秒读K字节数。是 rsect/s 的一半,因为每扇区大小为512字节
wkB/s 每秒写K字节数。是 wsect/s 的一半
avgrq-sz 平均每次设备I/O操作的数据大小 (扇区)
avgqu-sz 平均I/O队列长度
await 平均每次设备I/O操作的等待时间 (毫秒)
svctm 平均每次设备I/O操作的服务时间 (毫秒)
%util 一秒中有百分之多少的时间用于 I/O 操作,即被io消耗的cpu百分比

备注:如果 %util 接近 100%,说明产生的I/O请求太多,I/O系统已经满负荷,该磁盘可能存在瓶颈。如果 svctm 比较接近 await,说明 I/O 几乎没有等待时间;如果 await 远大于 svctm,说明I/O 队列太长,io响应太慢,则需要进行必要优化。如果avgqu-sz比较大,也表示有当量io在等待。

  • 定时显示所有信息
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
10
11
12
13
14
15
16
17
18
19
20
<span class="line">[root@ansheng ~]<span class="comment"># iostat 2 3</span></span>
<span class="line">Linux 2.6.32-573.22.1.el6.x86_64 (ansheng)      04/25/2016      _x86_64_        (2 CPU)</span>

<span class="line">avg-cpu:  %user   %nice %system %iowait  %steal   %idle</span>
<span class="line">           0.02    0.00    0.11    0.01    0.00   99.86</span>

<span class="line">Device:            tps   Blk_<span class="built_in">read</span>/s   Blk_wrtn/s   Blk_<span class="built_in">read</span>   Blk_wrtn</span>
<span class="line">sda               1.10        37.41         1.56      90604       3770</span>

<span class="line">avg-cpu:  %user   %nice %system %iowait  %steal   %idle</span>
<span class="line">           0.00    0.00    0.00    0.00    0.00  100.00</span>

<span class="line">Device:            tps   Blk_<span class="built_in">read</span>/s   Blk_wrtn/s   Blk_<span class="built_in">read</span>   Blk_wrtn</span>
<span class="line">sda               0.00         0.00         0.00          0          0</span>

<span class="line">avg-cpu:  %user   %nice %system %iowait  %steal   %idle</span>
<span class="line">           0.00    0.00    0.25    0.00    0.00   99.75</span>

<span class="line">Device:            tps   Blk_<span class="built_in">read</span>/s   Blk_wrtn/s   Blk_<span class="built_in">read</span>   Blk_wrtn</span>
<span class="line">sda               0.00         0.00         0.00          0          0</span>

每隔 2秒刷新显示,且显示3次

  • 显示指定磁盘信息
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">[root@ansheng ~]<span class="comment"># iostat -d sda1</span></span>
<span class="line">Linux 2.6.32-573.22.1.el6.x86_64 (ansheng)      04/25/2016      _x86_64_        (2 CPU)</span>

<span class="line">Device:            tps   Blk_<span class="built_in">read</span>/s   Blk_wrtn/s   Blk_<span class="built_in">read</span>   Blk_wrtn</span>
<span class="line">sda1              0.20         1.62         0.01       3986         18</span>
  • 以M为单位显示所有信息
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
6
7
8
<span class="line">[root@ansheng ~]<span class="comment"># iostat -m</span></span>
<span class="line">Linux 2.6.32-573.22.1.el6.x86_64 (ansheng)      04/25/2016      _x86_64_        (2 CPU)</span>

<span class="line">avg-cpu:  %user   %nice %system %iowait  %steal   %idle</span>
<span class="line">           0.02    0.00    0.11    0.01    0.00   99.86</span>

<span class="line">Device:            tps    MB_<span class="built_in">read</span>/s    MB_wrtn/s    MB_<span class="built_in">read</span>    MB_wrtn</span>
<span class="line">sda               1.08         0.02         0.00         44          1</span>

sar

概要: 系统活动情况报告

语法格式: sar [options] [-A] [-o file] t [n]

参数:

参数 概述
-A 所有报告的总和
-u 输出CPU使用情况的统计信息
-v 输出inode、文件和其他内核表的统计信息
-d 输出每一个块设备的活动信息
-r 输出内存和交换空间的统计信息
-b 显示I/O和传送速率的统计信息
-a 文件读写情况
-c 输出进程统计信息,每秒创建的进程数
-R 输出内存页面的统计信息
-y 终端设备活动情况
-w 输出系统交换活动信息

last

概要: 该命令用来列出目前与过去登录系统的用户相关信息。

语法格式: last [-R] [-num] [ -n num ] [-adiowx] [ -f file ] [ -t YYYYMMDDHHMMSS ] [name…] [tty…]

参数:

参数 说明
-a 将登录系统的的主机名称或IP地址,显示在最后一行
-d 将IP地址转换成主机名称
-f 指定记录文件,默认是显示/var/log目录下的wtmp文件的记录,但/var/log目录下得btmp能显示的内容更丰富,可以显示远程登录,例如ssh登录 ,包括失败的登录请求。
-i -i显示特定ip登录的情况。跟踪用 -i显示特定ip登录的情况。跟踪用
-n <显示列数>或-<显示列数> 设置列出名单的显示列数
-R 不显示登入系统的主机名称或IP(省略 hostname 的栏位)
-t 显示YYYYMMDDHHMMSS之前的信息
-x 显示系统关闭、用户登录和退出的历史

使用示例:

  • 显示最后登录系统的N条记录
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
10
11
12
13
<span class="line">[root@ansheng ~]<span class="comment"># last -10</span></span>
<span class="line">root     pts/0        172.16.10.1      Mon Apr 25 20:06   still logged <span class="keyword">in</span>   </span>
<span class="line">reboot   system boot  2.6.32-573.22.1. Mon Apr 25 20:04 - 20:07  (00:02)    </span>
<span class="line">root     pts/1        172.16.10.1      Mon Apr 25 16:22 - down   (02:50)    </span>
<span class="line">root     pts/0        172.16.10.1      Mon Apr 25 08:55 - down   (10:17)    </span>
<span class="line">reboot   system boot  2.6.32-573.22.1. Mon Apr 25 08:55 - 19:12  (10:17)    </span>
<span class="line">root     pts/0        172.16.10.1      Sun Apr 24 23:29 - down   (00:00)    </span>
<span class="line">root     pts/1        172.16.10.1      Sun Apr 24 21:28 - 22:28  (01:00)    </span>
<span class="line">root     pts/0        172.16.10.1      Sun Apr 24 21:24 - 22:42  (01:17)    </span>
<span class="line">reboot   system boot  2.6.32-573.22.1. Sun Apr 24 21:24 - 23:29  (02:04)    </span>
<span class="line">root     tty1                          Sun Apr 24 21:23 - down   (00:00)    </span>

<span class="line">wtmp begins Sat Apr  9 18:06:30 2016</span>
  • 将登录系统的主机名或IP地址显示在最后一行
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
10
11
12
13
<span class="line">[root@ansheng ~]<span class="comment"># last -10 -a</span></span>
<span class="line">root     pts/0        Mon Apr 25 20:06   still logged <span class="keyword">in</span>    172.16.10.1</span>
<span class="line">reboot   system boot  Mon Apr 25 20:04 - 20:07  (00:03)     2.6.32-573.22.1.el6.x86_64</span>
<span class="line">root     pts/1        Mon Apr 25 16:22 - down   (02:50)     172.16.10.1</span>
<span class="line">root     pts/0        Mon Apr 25 08:55 - down   (10:17)     172.16.10.1</span>
<span class="line">reboot   system boot  Mon Apr 25 08:55 - 19:12  (10:17)     2.6.32-573.22.1.el6.x86_64</span>
<span class="line">root     pts/0        Sun Apr 24 23:29 - down   (00:00)     172.16.10.1</span>
<span class="line">root     pts/1        Sun Apr 24 21:28 - 22:28  (01:00)     172.16.10.1</span>
<span class="line">root     pts/0        Sun Apr 24 21:24 - 22:42  (01:17)     172.16.10.1</span>
<span class="line">reboot   system boot  Sun Apr 24 21:24 - 23:29  (02:04)     2.6.32-573.22.1.el6.x86_64</span>
<span class="line">root     tty1         Sun Apr 24 21:23 - down   (00:00)     </span>

<span class="line">wtmp begins Sat Apr  9 18:06:30 2016</span>
  • 不显示登入系统的主机名称或IP地址
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
10
11
12
13
<span class="line">[root@ansheng ~]<span class="comment"># last -10 -R</span></span>
<span class="line">root     pts/0        Mon Apr 25 20:06   still logged <span class="keyword">in</span>   </span>
<span class="line">reboot   system boot  Mon Apr 25 20:04 - 20:08  (00:03)    </span>
<span class="line">root     pts/1        Mon Apr 25 16:22 - down   (02:50)    </span>
<span class="line">root     pts/0        Mon Apr 25 08:55 - down   (10:17)    </span>
<span class="line">reboot   system boot  Mon Apr 25 08:55 - 19:12  (10:17)    </span>
<span class="line">root     pts/0        Sun Apr 24 23:29 - down   (00:00)    </span>
<span class="line">root     pts/1        Sun Apr 24 21:28 - 22:28  (01:00)    </span>
<span class="line">root     pts/0        Sun Apr 24 21:24 - 22:42  (01:17)    </span>
<span class="line">reboot   system boot  Sun Apr 24 21:24 - 23:29  (02:04)    </span>
<span class="line">root     tty1         Sun Apr 24 21:23 - down   (00:00)    </span>

<span class="line">wtmp begins Sat Apr  9 18:06:30 2016</span>
  • 将IP地址转换成主机名称
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
10
11
12
13
<span class="line">[root@ansheng ~]<span class="comment"># last -10 -d</span></span>
<span class="line">root     pts/0        172.16.10.1      Mon Apr 25 20:06   still logged <span class="keyword">in</span>   </span>
<span class="line">reboot   system boot  0.0.0.0          Mon Apr 25 20:04 - 20:09  (00:04)    </span>
<span class="line">root     pts/1        172.16.10.1      Mon Apr 25 16:22 - down   (02:50)    </span>
<span class="line">root     pts/0        172.16.10.1      Mon Apr 25 08:55 - down   (10:17)    </span>
<span class="line">reboot   system boot  0.0.0.0          Mon Apr 25 08:55 - 19:12  (10:17)    </span>
<span class="line">root     pts/0        172.16.10.1      Sun Apr 24 23:29 - down   (00:00)    </span>
<span class="line">root     pts/1        172.16.10.1      Sun Apr 24 21:28 - 22:28  (01:00)    </span>
<span class="line">root     pts/0        172.16.10.1      Sun Apr 24 21:24 - 22:42  (01:17)    </span>
<span class="line">reboot   system boot  0.0.0.0          Sun Apr 24 21:24 - 23:29  (02:04)    </span>
<span class="line">root     tty1         0.0.0.0          Sun Apr 24 21:23 - down   (00:00)    </span>

<span class="line">wtmp begins Sat Apr  9 18:06:30 2016</span>

lastlog

概要: 用于显示系统中所有用户最近一次登录信息

语法格式: lastlog [选项]

参数:

参数 说明
-b<天数> 显示指定天数前的登录信息
-h 显示召集令的帮助信息
-t<天数> 显示指定天数以来的登录信息
-u<用户名> 显示指定用户的最近登录信息

使用示例:

  • 显示系统中所有用户最近一次登录信息
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<span class="line">[root@ansheng ~]<span class="comment"># lastlog </span></span>
<span class="line">Username         Port     From             Latest</span>
<span class="line">root             pts/0    172.16.10.1      Mon Apr 25 20:06:54 +0800 2016</span>
<span class="line">bin                                        **Never logged <span class="keyword">in</span>**</span>
<span class="line">daemon                                     **Never logged <span class="keyword">in</span>**</span>
<span class="line">adm                                        **Never logged <span class="keyword">in</span>**</span>
<span class="line">lp                                         **Never logged <span class="keyword">in</span>**</span>
<span class="line">sync                                       **Never logged <span class="keyword">in</span>**</span>
<span class="line">shutdown                                   **Never logged <span class="keyword">in</span>**</span>
<span class="line">halt                                       **Never logged <span class="keyword">in</span>**</span>
<span class="line">mail                                       **Never logged <span class="keyword">in</span>**</span>
<span class="line">uucp                                       **Never logged <span class="keyword">in</span>**</span>
<span class="line">operator                                   **Never logged <span class="keyword">in</span>**</span>
<span class="line">games                                      **Never logged <span class="keyword">in</span>**</span>
<span class="line">gopher                                     **Never logged <span class="keyword">in</span>**</span>
<span class="line">ftp                                        **Never logged <span class="keyword">in</span>**</span>
<span class="line">nobody                                     **Never logged <span class="keyword">in</span>**</span>
<span class="line">dbus                                       **Never logged <span class="keyword">in</span>**</span>
<span class="line">vcsa                                       **Never logged <span class="keyword">in</span>**</span>
<span class="line">abrt                                       **Never logged <span class="keyword">in</span>**</span>
<span class="line">haldaemon                                  **Never logged <span class="keyword">in</span>**</span>
<span class="line">ntp                                        **Never logged <span class="keyword">in</span>**</span>
<span class="line">apache                                     **Never logged <span class="keyword">in</span>**</span>
<span class="line">saslauth                                   **Never logged <span class="keyword">in</span>**</span>
<span class="line">postfix                                    **Never logged <span class="keyword">in</span>**</span>
<span class="line">sshd                                       **Never logged <span class="keyword">in</span>**</span>
<span class="line">stap-server                                **Never logged <span class="keyword">in</span>**</span>
<span class="line">oprofile                                   **Never logged <span class="keyword">in</span>**</span>
<span class="line">tcpdump                                    **Never logged <span class="keyword">in</span>**</span>
<span class="line">ansheng                                    **Never logged <span class="keyword">in</span>**</span>

history

概要: 查看执行过的命令

语法格式: history [n] history [-c] history [-raw] histfiles

参数:

参数 说明
n 数字,意思是‘要列出最近的 n 笔命令列表’的意思
-c 将目前的 shell 中的所有 history 内容全部消除
-a 将目前新增的 history 指令新增入 histfiles 中
-r 将 histfiles 的内容读到目前这个 shell 的 history 记忆中
-w 将目前的 history 记忆内容写入 histfiles 中
-d 删除指定行的记录

使用示例:

  • 列出目前记录的所有history后10行
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
10
11
<span class="line">[root@ansheng ~]<span class="comment"># history |tail -10</span></span>
<span class="line">  436  last -10 -R</span>
<span class="line">  437  last -n 10 <span class="_">-f</span> /var/<span class="built_in">log</span>/btmp</span>
<span class="line">  438  cat /var/<span class="built_in">log</span>/btmp </span>
<span class="line">  439  last -10 <span class="_">-d</span></span>
<span class="line">  440  man <span class="built_in">history</span> </span>
<span class="line">  441  <span class="built_in">history</span> </span>
<span class="line">  442  ls</span>
<span class="line">  443  man <span class="built_in">history</span> </span>
<span class="line">  444  <span class="built_in">history</span> </span>
<span class="line">  445  <span class="built_in">history</span> |tail -10</span>
  • 清空history当前所有历史命令的记录
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
10
11
12
13
14
<span class="line">[root@ansheng ~]<span class="comment"># history 10</span></span>
<span class="line">  455  <span class="built_in">history</span> -10</span>
<span class="line">  456  <span class="built_in">history</span> 10</span>
<span class="line">  457  <span class="built_in">history</span> <span class="_">-d</span> 450</span>
<span class="line">  458  <span class="built_in">history</span> 10</span>
<span class="line">  459  ls</span>
<span class="line">  460  <span class="built_in">pwd</span></span>
<span class="line">  461  ifconfig </span>
<span class="line">  462  <span class="built_in">history</span> 10</span>
<span class="line">  463  <span class="built_in">history</span> <span class="_">-d</span> 460</span>
<span class="line">  464  <span class="built_in">history</span> 10</span>
<span class="line">[root@ansheng ~]<span class="comment"># history -c</span></span>
<span class="line">[root@ansheng ~]<span class="comment"># history </span></span>
<span class="line">    1  <span class="built_in">history</span></span>
admin
版权声明:本站原创文章,由admin2016-07-12发表,共计13393字。
转载提示:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)