1.wc的使用
统计一个目录下的文件个数
[root@localhost etc]# cd /var/log/
[root@localhost log]# ll | grep '^-'|wc -l
53
[root@localhost log]
拓展:关于命令wc的使用
wc -c filename: 显示一个文件的字节数
wc -m filename:显示一个文件的字符数
wc -l filename: 显示一个文件的行数
wc -L filename: 显示一个文件中的最长行的长度
wc -w filename:显示一个文件的字数
2.查看磁盘使用情况df -h,df -i
[root@localhost log]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 18G 5.2G 12G 31% /
tmpfs 931M 80K 931M 1% /dev/shm
/dev/sda1 291M 39M 238M 14% /boot
[root@localhost log]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda2 1160992 135207 1025785 12% /
tmpfs 238319 5 238314 1% /dev/shm
/dev/sda1 76912 39 76873 1% /boot
3.查看系统服务器cpu负载,w,uptime,top
[root@localhost log]# w
23:47:04 up 3 days, 3:27, 4 users, load average: 0.00, 0.00, 0.00
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 :0 31Jul19 18days 34.55s 34.55s /usr/bin/Xorg :0 -nr -verbose -audit 4 -auth /var/run/gdm/auth-for-gdm-Lw1QHq/database -nolisten tcp vt1
root pts/0 :0.0 31Jul19 18days 0.00s 0.00s /bin/bash
root pts/2 192.168.197.1 10:24 13:07m 0.12s 0.12s -bash
root pts/3 192.168.197.1 23:31 0.00s 0.22s 0.00s w
[root@localhost log]# uptime
23:47:08 up 3 days, 3:27, 4 users, load average: 0.00, 0.00, 0.00
[root@localhost log]# top
top - 23:47:13 up 3 days, 3:27, 4 users, load average: 0.00, 0.00, 0.00
Tasks: 145 total, 1 running, 144 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.2%us, 0.2%sy, 0.0%ni, 99.5%id, 0.0%wa, 0.0%hi, 0.1%si, 0.0%st
Mem: 1906556k total, 1438512k used, 468044k free, 201512k buffers
Swap: 2097144k total, 0k used, 2097144k free, 746700k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
28695 root 20 0 15028 1136 828 R 2.8 0.1 0:00.27 top
1285 root 20 0 254m 8208 4908 S 1.4 0.4 6:49.51 vmtoolsd
1 root 20 0 19356 1536 1228 S 0.0 0.1 0:01.92 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
4 root 20 0 0 0 0 S 0.0 0.0 0:02.34 ksoftirqd/0
动态监控进程top介绍
4.查看内存使用情况free,free -m,top
[root@localhost log]# free
total used free shared buffers cached
Mem: 1906556 1438380 468176 0 201512 746708
-/+ buffers/cache: 490160 1416396
Swap: 2097144 0 2097144
[root@localhost log]# free -m
total used free shared buffers cached
Mem: 1861 1404 457 0 196 729
-/+ buffers/cache: 478 1383
Swap: 2047 0 2047
[root@localhost log]# top
top - 23:51:17 up 3 days, 3:31, 4 users, load average: 0.00, 0.00, 0.00
Tasks: 145 total, 1 running, 144 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.3%sy, 0.0%ni, 99.3%id, 0.0%wa, 0.0%hi, 0.3%si, 0.0%st
Mem: 1906556k total, 1438544k used, 468012k free, 201512k buffers
Swap: 2097144k total, 0k used, 2097144k free, 746708k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
7 root 20 0 0 0 0 S 0.3 0.0 5:34.47 events/0
2446 root 20 0 269m 21m 13m S 0.3 1.1 6:55.87 vmtoolsd
28725 root 20 0 15032 1256 940 R 0.3 0.1 0:00.01 top
1 root 20 0 19356 1536 1228 S 0.0 0.1 0:01.92 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
4 root 20 0 0 0 0 S 0.0 0.0 0:02.34 ksoftirqd/0
5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
6 root RT 0 0 0 0 S 0.0 0.0 0:00.83 watchdog/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cgroup
5.查看正在运行的进程服务程序的信息netstat -antp,ss -natp
[root@localhost log]# netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1818/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1716/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2063/master
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2014/mysqld
tcp 0 0 192.168.197.150:22 192.168.197.1:51871 ESTABLISHED 27646/sshd
tcp 0 96 192.168.197.150:22 192.168.197.1:57590 ESTABLISHED 28550/sshd
tcp 0 0 :::80 :::* LISTEN 2095/httpd
tcp 0 0 :::22 :::* LISTEN 1818/sshd
tcp 0 0 ::1:631 :::* LISTEN 1716/cupsd
tcp 0 0 ::1:25 :::* LISTEN 2063/master
[root@localhost log]# ss -natp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::80 :::* users:(("httpd",2095,4),("httpd",27920,4),("httpd",27921,4),("httpd",27922,4),("httpd",27923,4),("httpd",27924,4),("httpd",27925,4),("httpd",27926,4),("httpd",27927,4))
LISTEN 0 128 *:22 *:* users:(("sshd",1818,4))
LISTEN 0 128 :::22 :::* users:(("sshd",1818,3))
LISTEN 0 128 127.0.0.1:631 *:* users:(("cupsd",1716,7))
LISTEN 0 128 ::1:631 :::* users:(("cupsd",1716,6))
LISTEN 0 100 ::1:25 :::* users:(("master",2063,13))
LISTEN 0 100 127.0.0.1:25 *:* users:(("master",2063,12))
LISTEN 0 50 *:3306 *:* users:(("mysqld",2014,4))
ESTAB 0 0 192.168.197.150:22 192.168.197.1:51871 users:(("sshd",27646,3))
ESTAB 0 96 192.168.197.150:22 192.168.197.1:57590 users:(("sshd",28550,3))
[root@localhost log]#
6.打印文件的前三行head,sed,awk
[root@localhost tmp]# cat passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
head -3 passwd
[root@localhost tmp]# head -3 passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
sed -n ‘1,3p’ passwd
[root@localhost tmp]# sed -n '1,3p' passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
awk ‘NR<4{print$0}’ passwd
[root@localhost tmp]# awk 'NR<4{print$0}' passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
[root@localhost tmp]#
7.名词解释
Swap: 虚拟内存
在Linux下,SWAP的作用类似Windows系统下的“虚拟内存”。当物理内存不足时,拿出部分硬盘空间当SWAP分区(虚拟成内存)使用,从而解决内存容量不足的情况。
raid :磁盘阵列
在磁盘的使用中,有时候需要提高磁盘的读写数据速度,就要用到磁盘组——raid,也就是磁盘阵列。
磁盘阵列是由最少两块以上的磁盘组成的,raid有许多模式,在这里将介绍其中常用的模式raid0、raid1和raid5。
raid0:raid0是用来提高读取数据速度的,其用两块以上的磁盘组成,是将数据同时记录在这几个磁盘中,在使用时,几块磁盘各读取一部分数据。这种磁盘组因为需要存入的数据完全相同,所以容量和一块磁盘的容量大小相同,但是读取速度会变快。
raid1:raid1是用来提高写入数据速度的,是在写入数据时将数据分成磁盘的份数分别存在几块磁盘中的,每个磁盘当中都是不完整的数据,所以这种磁盘组的容量将会翻倍,写入数据的速度也会变快。
raid5:raid5本质上就是raid0和raid1的结合,使得读取数据和写入数据速度都提高,但是加速的结果不如raid0或者raid1高。
8.ps -aux
[root@localhost tmp]# ps -aux
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 19356 1536 ? Ss Aug15 0:01 /sbin/init
root 2 0.0 0.0 0 0 ? S Aug15 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S Aug15 0:00 [migration/0]
root 4 0.0 0.0 0 0 ? S Aug15 0:02 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S Aug15 0:00 [migration/0]
root 6 0.0 0.0 0 0 ? S Aug15 0:00 [watchdog/0]
root 7 0.1 0.0 0 0 ? S Aug15 5:37 [events/0]
root 8 0.0 0.0 0 0 ? S Aug15 0:00 [cgroup]
root 9 0.0 0.0 0 0 ? S Aug15 0:00 [khelper]
root 10 0.0 0.0 0 0 ? S Aug15 0:00 [netns]
root 11 0.0 0.0 0 0 ? S Aug15 0:00 [async/mgr]
8. 查看网卡详细信息 ethtool eth0
[root@localhost tmp]# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
MDI-X: Unknown
Supports Wake-on: d
Wake-on: d
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes
[root@localhost tmp]#