摘要:本文主要介绍了linux的高级指令。主要包括:hostname、id、whoami、ps -ef、top、du -sh、find、service、kill、ifconfig、reboot、shutdown、uptime、uname、netstat-tnlp、man共计16个。
1、高级指令
1.1 hostname指令
作用:操作服务器的主机名(读取、设置)
语法1:#hostname
含义:表示输出完整的主机名
语法2:#hostname -f
含义:表示输出当前主机名中的FQDN(全限定域名)
代码示例:
1 [root@localhost ~]# hostname 2 localhost.localdomain 3 [root@localhost ~]# hostname -f 4 localhost
1.2 id指令
作用:查看一个用户的一些基本信息(包含用户id,用户组id,附加组id…),该指令如果不指定用户则默认当前用户。
语法1:#id
默认显示当前执行该命令的用户的基本信息
语法2:#id 用户名
显示指定用户的基本信息
代码示例:
1 [root@localhost ~]# id 2 uid=0(root) gid=0(root) 组=0(root) 3 [root@localhost ~]# id lzy 4 uid=1000(lzy) gid=1000(lzy) 组=1000(lzy),10(wheel)
验证上述信息是否正确?
验证用户信息:通过文件/etc/passwd
验证用户组信息:通过文件/etc/group
经验证,显示正确,此处不再赘述。
1.3 whoami指令
作用:“我是谁?”显示当前登录的用户名,一般用于shell脚本,用于获取当前操作的用户名方便记录日志。
语法:#whoami
代码示例:
1 [root@localhost ~]# whoami 2 root
1.4 ps -ef指令(重点)
作用:主要是查看服务器的进程信息
选项含义:
-e:等价于“-A”,表示列出全部的进程
-f:显示全部的列(显示全字段)
代码示例:
1 [root@localhost ~]# ps -ef 2 UID PID PPID C STIME TTY TIME CMD 3 root 1 0 0 10:47 ? 00:00:01 /usr/lib/systemd/systemd --switched-r 4 root 2 0 0 10:47 ? 00:00:00 [kthreadd] 5 root 3 2 0 10:47 ? 00:00:00 [ksoftirqd/0] 6 root 4 2 0 10:47 ? 00:00:00 [kworker/0:0] 7 root 5 2 0 10:47 ? 00:00:00 [kworker/0:0H] 8 root 6 2 0 10:47 ? 00:00:00 [kworker/u256:0] 9 root 7 2 0 10:47 ? 00:00:00 [migration/0] 10 root 8 2 0 10:47 ? 00:00:00 [rcu_bh] 11 root 9 2 0 10:47 ? 00:00:00 [rcu_sched] 12 root 10 2 0 10:47 ? 00:00:00 [watchdog/0] 13 root 12 2 0 10:47 ? 00:00:00 [kdevtmpfs] 14 root 13 2 0 10:47 ? 00:00:00 [netns] 15 root 14 2 0 10:47 ? 00:00:00 [khungtaskd] 16 root 15 2 0 10:47 ? 00:00:00 [writeback] 17 root 16 2 0 10:47 ? 00:00:00 [kintegrityd] 18 root 17 2 0 10:47 ? 00:00:00 [bioset] 19 root 18 2 0 10:47 ? 00:00:00 [kblockd] 20 root 19 2 0 10:47 ? 00:00:00 [md] 21 root 25 2 0 10:47 ? 00:00:00 [kswapd0] 22 root 26 2 0 10:47 ? 00:00:00 [ksmd] 23 root 27 2 0 10:47 ? 00:00:03 [khugepaged] 24 root 28 2 0 10:47 ? 00:00:00 [crypto] 25 root 36 2 0 10:47 ? 00:00:00 [kthrotld] 26 root 38 2 0 10:47 ? 00:00:00 [kmpath_rdacd] 27 root 39 2 0 10:47 ? 00:00:00 [kpsmoused] 28 root 41 2 0 10:47 ? 00:00:00 [ipv6_addrconf] 29 root 60 2 0 10:47 ? 00:00:00 [deferwq] 30 root 92 2 0 10:47 ? 00:00:00 [kauditd] 31 root 271 2 0 10:47 ? 00:00:00 [mpt_poll_0] 32 root 272 2 0 10:47 ? 00:00:00 [ata_sff] 33 root 273 2 0 10:47 ? 00:00:00 [mpt/0] 34 root 281 2 0 10:47 ? 00:00:00 [scsi_eh_0] 35 root 282 2 0 10:47 ? 00:00:00 [scsi_tmf_0] 36 root 283 2 0 10:47 ? 00:00:00 [scsi_eh_1] 37 root 285 2 0 10:47 ? 00:00:00 [scsi_tmf_1] 38 root 287 2 0 10:47 ? 00:00:00 [scsi_eh_2] 39 root 289 2 0 10:47 ? 00:00:00 [scsi_tmf_2] 40 root 290 2 0 10:47 ? 00:00:00 [kworker/u256:2] 41 root 291 2 0 10:47 ? 00:00:00 [ttm_swap] 42 root 363 2 0 10:47 ? 00:00:00 [kdmflush] 43 root 364 2 0 10:47 ? 00:00:00 [bioset] 44 root 375 2 0 10:47 ? 00:00:00 [kdmflush] 45 root 376 2 0 10:47 ? 00:00:00 [bioset] 46 root 389 2 0 10:47 ? 00:00:00 [bioset] 47 root 390 2 0 10:47 ? 00:00:00 [xfsalloc] 48 root 391 2 0 10:47 ? 00:00:00 [xfs_mru_cache] 49 root 392 2 0 10:47 ? 00:00:00 [xfs-buf/dm-0] 50 root 393 2 0 10:47 ? 00:00:00 [xfs-data/dm-0] 51 root 394 2 0 10:47 ? 00:00:00 [xfs-conv/dm-0] 52 root 395 2 0 10:47 ? 00:00:00 [xfs-cil/dm-0] 53 root 396 2 0 10:47 ? 00:00:00 [xfs-reclaim/dm-] 54 root 397 2 0 10:47 ? 00:00:00 [xfs-log/dm-0] 55 root 398 2 0 10:47 ? 00:00:00 [xfs-eofblocks/d] 56 root 399 2 0 10:47 ? 00:00:00 [xfsaild/dm-0] 57 root 471 1 0 10:47 ? 00:00:00 /usr/lib/systemd/systemd-journald 58 root 493 1 0 10:47 ? 00:00:00 /usr/sbin/lvmetad -f 59 root 500 2 0 10:47 ? 00:00:00 [rpciod] 60 root 501 2 0 10:47 ? 00:00:00 [xprtiod] 61 root 508 1 0 10:47 ? 00:00:00 /usr/lib/systemd/systemd-udevd 62 root 522 2 0 10:47 ? 00:00:00 [nfit] 63 root 534 2 0 10:47 ? 00:00:00 [kworker/0:1H] 64 root 596 2 0 10:47 ? 00:00:00 [xfs-buf/sda1] 65 root 597 2 0 10:47 ? 00:00:00 [xfs-data/sda1] 66 root 598 2 0 10:47 ? 00:00:00 [xfs-conv/sda1] 67 root 599 2 0 10:47 ? 00:00:00 [xfs-cil/sda1] 68 root 600 2 0 10:47 ? 00:00:00 [xfs-reclaim/sda] 69 root 601 2 0 10:47 ? 00:00:00 [xfs-log/sda1] 70 root 602 2 0 10:47 ? 00:00:00 [xfs-eofblocks/s] 71 root 603 2 0 10:47 ? 00:00:00 [xfsaild/sda1] 72 root 608 2 0 10:47 ? 00:00:00 [kdmflush] 73 root 609 2 0 10:47 ? 00:00:00 [bioset] 74 root 616 2 0 10:47 ? 00:00:00 [xfs-buf/dm-2] 75 root 617 2 0 10:47 ? 00:00:00 [xfs-data/dm-2] 76 root 618 2 0 10:47 ? 00:00:00 [xfs-conv/dm-2] 77 root 619 2 0 10:47 ? 00:00:00 [xfs-cil/dm-2] 78 root 620 2 0 10:47 ? 00:00:00 [xfs-reclaim/dm-] 79 root 621 2 0 10:47 ? 00:00:00 [xfs-log/dm-2] 80 root 622 2 0 10:47 ? 00:00:00 [xfs-eofblocks/d] 81 root 623 2 0 10:47 ? 00:00:00 [xfsaild/dm-2] 82 root 651 1 0 10:47 ? 00:00:00 /sbin/auditd 83 root 653 651 0 10:47 ? 00:00:00 /sbin/audispd 84 root 656 653 0 10:47 ? 00:00:00 /usr/sbin/sedispatch 85 root 676 1 0 10:47 ? 00:00:00 /usr/sbin/smartd -n -q never 86 root 677 1 0 10:47 ? 00:00:00 /usr/sbin/ModemManager 87 root 678 1 0 10:47 ? 00:00:00 /usr/lib/systemd/systemd-logind 88 root 679 1 0 10:47 ? 00:00:00 /usr/libexec/accounts-daemon 89 rtkit 682 1 0 10:47 ? 00:00:00 /usr/libexec/rtkit-daemon 90 root 685 1 0 10:47 ? 00:00:00 /usr/bin/VGAuthService -s 91 root 686 1 0 10:47 ? 00:00:01 /usr/bin/vmtoolsd 92 libstor+ 690 1 0 10:47 ? 00:00:00 /usr/bin/lsmd -d 93 polkitd 691 1 0 10:47 ? 00:00:00 /usr/lib/polkit-1/polkitd --no-debug 94 root 695 1 0 10:47 ? 00:00:00 /usr/sbin/abrtd -d -s 95 root 696 1 0 10:47 ? 00:00:00 /usr/bin/abrt-watch-log -F Backtrace 96 root 697 1 0 10:47 ? 00:00:00 /usr/bin/abrt-watch-log -F BUG: WARNI 97 root 698 1 0 10:47 ? 00:00:00 /usr/sbin/alsactl -s -n 19 -c -E ALSA 98 root 705 1 0 10:47 ? 00:00:00 /usr/sbin/rsyslogd -n 99 dbus 706 1 0 10:47 ? 00:00:00 /bin/dbus-daemon --system --address=s 100 chrony 716 1 0 10:47 ? 00:00:00 /usr/sbin/chronyd 101 root 725 1 0 10:47 ? 00:00:00 /usr/sbin/gssproxy -D 102 root 757 1 0 10:47 ? 00:00:00 /sbin/rngd -f 103 avahi 759 1 0 10:47 ? 00:00:00 avahi-daemon: running [linux.local] 104 root 771 1 0 10:47 ? 00:00:00 /bin/bash /usr/sbin/ksmtuned 105 root 775 1 0 10:47 ? 00:00:00 /usr/sbin/mcelog --ignorenodev --daem 106 avahi 785 759 0 10:47 ? 00:00:00 avahi-daemon: chroot helper 107 root 788 1 0 10:47 ? 00:00:01 /usr/bin/python -Es /usr/sbin/firewal 108 root 789 1 0 10:47 ? 00:00:00 /usr/sbin/NetworkManager --no-daemon 109 root 1024 1 0 10:47 ? 00:00:00 /usr/bin/python -Es /usr/sbin/tuned - 110 root 1027 1 0 10:47 ? 00:00:00 /usr/sbin/cupsd -f 111 root 1031 1 0 10:47 ? 00:00:00 /usr/sbin/sshd -D 112 root 1034 1 0 10:47 ? 00:00:00 /usr/sbin/libvirtd 113 root 1040 1 0 10:47 ? 00:00:00 /usr/sbin/crond -n 114 root 1044 1 0 10:47 ? 00:00:00 /usr/sbin/gdm 115 root 1052 1 0 10:47 ? 00:00:00 /usr/sbin/atd -f 116 root 1270 1 0 10:47 ? 00:00:00 /usr/libexec/postfix/master -w 117 root 1272 1044 0 10:47 tty1 00:00:03 /usr/bin/X :0 -background none -nores 118 postfix 1273 1270 0 10:47 ? 00:00:00 pickup -l -t unix -u 119 postfix 1274 1270 0 10:47 ? 00:00:00 qmgr -l -t unix -u 120 nobody 1438 1 0 10:48 ? 00:00:00 /usr/sbin/dnsmasq --conf-file=/var/li 121 root 1440 1438 0 10:48 ? 00:00:00 /usr/sbin/dnsmasq --conf-file=/var/li 122 root 1505 1 0 10:48 ? 00:00:00 /usr/libexec/upowerd 123 root 1553 1 0 10:48 ? 00:00:00 /usr/libexec/packagekitd 124 root 1560 1 0 10:48 ? 00:00:00 /usr/sbin/wpa_supplicant -u -f /var/l 125 colord 1578 1 0 10:48 ? 00:00:00 /usr/libexec/colord 126 root 1638 1044 0 10:48 ? 00:00:00 gdm-session-worker [pam/gdm-password] 127 root 1647 1 0 10:48 ? 00:00:00 /usr/bin/gnome-keyring-daemon --daemo 128 gdm 1651 1 0 10:48 ? 00:00:00 ibus-daemon --xim --panel disable 129 gdm 1654 1651 0 10:48 ? 00:00:00 /usr/libexec/ibus-dconf 130 gdm 1657 1 0 10:48 ? 00:00:00 /usr/libexec/ibus-x11 --kill-daemon 131 root 1666 1638 0 10:48 ? 00:00:00 /usr/libexec/gnome-session-binary --s 132 root 1673 1 0 10:48 ? 00:00:00 dbus-launch --sh-syntax --exit-with-s 133 root 1674 1 0 10:48 ? 00:00:00 /bin/dbus-daemon --fork --print-pid 4 134 root 1731 1 0 10:48 ? 00:00:00 /usr/libexec/gvfsd 135 root 1736 1 0 10:48 ? 00:00:00 /usr/libexec/gvfsd-fuse /run/user/0/g 136 root 1828 1666 0 10:48 ? 00:00:00 /usr/bin/ssh-agent /bin/sh -c exec -l 137 root 1843 1 0 10:48 ? 00:00:00 /usr/libexec/at-spi-bus-launcher 138 root 1848 1843 0 10:48 ? 00:00:00 /bin/dbus-daemon --config-file=/usr/s 139 root 1852 1 0 10:48 ? 00:00:00 /usr/libexec/at-spi2-registryd --use- 140 root 1869 1666 1 10:48 ? 00:00:13 /usr/bin/gnome-shell 141 root 1876 1869 0 10:48 ? 00:00:00 ibus-daemon --xim --panel disable 142 root 1881 1876 0 10:48 ? 00:00:00 /usr/libexec/ibus-dconf 143 root 1885 1 0 10:48 ? 00:00:00 /usr/libexec/ibus-x11 --kill-daemon 144 root 1891 1 0 10:48 ? 00:00:00 /usr/libexec/gnome-shell-calendar-ser 145 root 1894 1 0 10:48 ? 00:00:00 /usr/libexec/xdg-permission-store 146 root 1902 1 0 10:48 ? 00:00:00 /usr/libexec/mission-control-5 147 root 1904 1 0 10:48 ? 00:00:00 /usr/libexec/gvfs-udisks2-volume-moni 148 root 1909 1 0 10:48 ? 00:00:00 /usr/libexec/goa-daemon 149 root 1914 1 0 10:48 ? 00:00:00 /usr/lib/udisks2/udisksd --no-debug 150 root 1922 1 0 10:48 ? 00:00:00 /usr/libexec/gvfs-mtp-volume-monitor 151 root 1927 1 0 10:48 ? 00:00:00 /usr/libexec/gvfs-gphoto2-volume-moni 152 root 1932 1 0 10:48 ? 00:00:00 /usr/libexec/gvfs-afc-volume-monitor 153 root 1938 1 0 10:48 ? 00:00:00 /usr/libexec/gvfs-goa-volume-monitor 154 root 1948 1 0 10:48 ? 00:00:00 /usr/libexec/evolution-source-registr 155 root 1954 1 0 10:48 ? 00:00:00 /usr/libexec/goa-identity-service 156 root 1972 1666 0 10:48 ? 00:00:00 /usr/libexec/gnome-settings-daemon 157 root 1981 1 0 10:48 ? 00:00:00 /usr/bin/pulseaudio --start 158 root 1991 1666 0 10:48 ? 00:00:00 nautilus-desktop --force 159 root 1993 1 0 10:48 ? 00:00:00 /usr/libexec/gsd-printer 160 root 2004 1 0 10:48 ? 00:00:00 /usr/libexec/gvfsd-trash --spawner :1 161 root 2014 1 0 10:48 ? 00:00:00 /usr/libexec/evolution-calendar-facto 162 root 2015 1666 0 10:48 ? 00:00:00 abrt-applet 163 root 2016 1666 0 10:48 ? 00:00:00 /usr/bin/gnome-software --gapplicatio 164 root 2020 1 0 10:48 ? 00:00:01 /usr/bin/vmtoolsd -n vmusr 165 root 2032 1876 0 10:48 ? 00:00:00 /usr/libexec/ibus-engine-simple 166 root 2035 1666 0 10:48 ? 00:00:00 /usr/libexec/tracker-extract 167 root 2044 1666 0 10:48 ? 00:00:00 /usr/libexec/tracker-miner-apps 168 root 2049 1666 0 10:48 ? 00:00:00 /usr/libexec/tracker-miner-fs 169 root 2051 1666 0 10:48 ? 00:00:00 /usr/libexec/tracker-miner-user-guide 170 root 2075 1 0 10:48 ? 00:00:00 /usr/libexec/tracker-store 171 root 2148 2014 0 10:48 ? 00:00:00 /usr/libexec/evolution-calendar-facto 172 root 2149 1 0 10:48 ? 00:00:00 /usr/libexec/dconf-service 173 root 2176 2014 0 10:48 ? 00:00:00 /usr/libexec/evolution-calendar-facto 174 root 2233 1 0 10:48 ? 00:00:00 /usr/libexec/evolution-addressbook-fa 175 root 2303 2233 0 10:48 ? 00:00:00 /usr/libexec/evolution-addressbook-fa 176 root 2497 1 0 10:51 ? 00:00:01 /usr/libexec/gnome-terminal-server 177 root 2503 2497 0 10:51 ? 00:00:00 gnome-pty-helper 178 root 2506 2497 0 10:51 pts/0 00:00:00 bash 179 root 2619 2 0 10:55 ? 00:00:00 [kworker/0:3] 180 root 2693 2 0 11:00 ? 00:00:00 [kworker/0:1] 181 root 2705 1 0 11:01 ? 00:00:00 /usr/sbin/anacron -s 182 root 2722 2 0 11:01 ? 00:00:00 [kworker/0:2] 183 root 2762 771 0 11:05 ? 00:00:00 sleep 60 184 root 2763 1 0 11:05 ? 00:00:00 /usr/libexec/fprintd 185 root 2778 1 0 11:06 ? 00:00:00 /usr/lib/systemd/systemd-hostnamed 186 root 2785 1 0 11:06 ? 00:00:00 /usr/libexec/gvfsd-metadata 187 root 2793 2506 0 11:06 pts/0 00:00:00 ps -ef
解释:
- UID:该进程执行的用户id;
- PID:进程id;
- PPID:该进程的父级进程id,如果一个程序的父级进程找不到,该程序的进程称之为僵尸进程(parent process ID);
- C:Cpu的占用率,其形式是百分数;
- STIME:进行的启动时间;
- TTY:终端设备,发起该进程的设备识别符号,如果显示“?”则表示该进程并不是由终端设备发起;
- TIME:进程的执行时间;
- CMD:该进程的名称或者对应的路径;
案例:(100%使用的命令)在ps的结果中过滤出想要查看的进程状态
#ps -ef|grep “进程名称”:
代码示例:
1 [root@localhost ~]# ps -ef|grep bash 2 root 771 1 0 10:47 ? 00:00:00 /bin/bash /usr/sbin/ksmtuned 3 root 1828 1666 0 10:48 ? 00:00:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "env GNOME_SHELL_SESSION_MODE=classic gnome-session --session gnome-classic" 4 root 2506 2497 0 10:51 pts/0 00:00:00 bash 5 root 3013 2506 0 11:20 pts/0 00:00:00 grep --color=auto bash
1.5 top指令(重点)
作用:查看服务器的进程占的资源(100%使用)
语法:
- 进入命令:#top(动态显示)
- 退出命令:按下q键
代码示例:
1 top - 11:29:06 up 43 min, 2 users, load average: 0.01, 0.19, 0.19 2 Tasks: 184 total, 1 running, 183 sleeping, 0 stopped, 0 zombie 3 %Cpu(s): 7.9 us, 1.4 sy, 0.0 ni, 90.6 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st 4 KiB Mem : 1867024 total, 509084 free, 702900 used, 655040 buff/cache 5 KiB Swap: 2097148 total, 2097148 free, 0 used. 952164 avail Mem 6 7 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 8 1869 root 20 0 1642584 188580 51892 S 5.3 10.1 0:48.06 gnome-shell 9 1272 root 20 0 281976 26868 10236 S 4.0 1.4 0:18.26 X 10 2497 root 20 0 739904 29216 16676 S 3.3 1.6 0:05.90 gnome-terminal- 11 3044 root 20 0 0 0 0 S 0.3 0.0 0:00.43 kworker/0:0 12 3359 root 20 0 157716 2272 1556 R 0.3 0.1 0:00.14 top 13 1 root 20 0 125504 3964 2500 S 0.0 0.2 0:02.22 systemd 14 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 15 3 root 20 0 0 0 0 S 0.0 0.0 0:00.19 ksoftirqd/0 16 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H 17 7 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/0 18 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 19 9 root 20 0 0 0 0 S 0.0 0.0 0:00.84 rcu_sched 20 10 root rt 0 0 0 0 S 0.0 0.0 0:00.22 watchdog/0 21 12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs 22 13 root 0 -20 0 0 0 S 0.0 0.0 0:00.01 netns 23 14 root 20 0 0 0 0 S 0.0 0.0 0:00.00 khungtaskd 24 15 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback 25 16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kintegrityd 26 17 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset
表头含义:
- PID:进程id;
- USER:该进程对应的用户;
- PR:优先级;
- VIRT:虚拟内存;
- RES:常驻内存;
- SHR:共享内存; 计算一个进程实际使用的内存 = 常驻内存(RES)- 共享内存(SHR)
- S:表示进程的状态status(sleeping,其中S表示睡眠,R表示运行);
- %CPU:表示CPU的占用百分比;
- %MEM:表示内存的占用百分比;
- TIME+:执行的时间;
- COMMAND:进程的名称或者路径;
在运行top的时候,可以按下方便的快捷键:
M:表示将结果按照内存(MEM)从高到低进行降序排列;
P:表示将结果按照CPU使用率从高到低进行降序排列;
1:当服务器拥有多个cpu的时候可以使用“1”快捷键来切换是否展示显示各个cpu的详细信息;
1.6 du -sh指令
作用:查看目录的真实大小
语法:#du -sh 目录路径
选项含义:
-s:summaries,只显示汇总的大小
-h:表示以高可读性的形式进行显示
代码示例:
1 [root@localhost ~]# du -sh ./001 2 8.0K ./001
1.7 find指令
作用:用于查找文件(其参数有55个之多)
语法:#find 路径范围 选项 选项的值
选项含义:
- -name:按照文档名称进行搜索(支持模糊搜索)
- -type:按照文档的类型进行搜索
文档类型:“-”表示文件(在使用find的时候需要用f来替换),“d”表示文件夹
代码示例(一):按照名字查找某个文件
1 [root@localhost ~]# find / -name 829976354.txt 2 /root/001/829976354.txt
代码示例(二):搜索目录下txt后缀的文件
1 [root@localhost ~]# find /root -name *.txt 2 /root/001/002.txt 3 /root/002.txt
代码示例(三):搜索某个目录下的所有文件(由于文件太多,只列出部分)
1 [root@localhost ~]# find /etc/sane.d/ -type f 2 /etc/sane.d/abaton.conf 3 /etc/sane.d/ricoh.conf 4 /etc/sane.d/agfafocus.conf 5 /etc/sane.d/apple.conf 6 /etc/sane.d/artec.conf 7 /etc/sane.d/rts8891.conf 8 /etc/sane.d/artec_eplus48u.conf 9 /etc/sane.d/s9036.conf 10 /etc/sane.d/avision.conf
查看该目录下所有文件的数目:
1 [root@localhost ~]# find /etc/sane.d/ -type f|wc -l 2 78
代码示例(四):搜索某个目录下的所有文件夹(数目太多,只列出部分):
1 [root@localhost ~]# find /etc -type d 2 /etc 3 /etc/fonts 4 /etc/fonts/conf.d 5 /etc/grub.d 6 /etc/pki 7 /etc/pki/rpm-gpg 8 /etc/pki/ca-trust 9 /etc/pki/ca-trust/extracted 10 /etc/pki/ca-trust/extracted/java 11 /etc/pki/ca-trust/extracted/openssl 12 /etc/pki/ca-trust/extracted/pem 13 /etc/pki/ca-trust/source 14 ...
查看该目录下所有文件夹的数目:
1 [root@localhost ~]# find /etc -type d|wc -l 2 725
1.8 service指令(重点)
作用:用于控制一些软件的服务启动/停止/重启
语法:#service 服务名 start/stop/restart
1.9 kill指令(重点)
作用:表示杀死进程(当遇到僵尸进程或者出于某些原因需要关闭进程的时候)
语法:#kill 进程PID(语法需要配合ps一起使用)
代码示例:
1 [root@localhost ~]# ps -ef|grep firefox 2 root 8354 1 0 15:51 ? 00:00:38 /usr/lib64/firefox/firefox 3 root 8429 8354 0 15:51 ? 00:00:04 /usr/lib64/firefox/plugin-container -greomni /usr/lib64/firefox/omni.ja -appomni /usr/lib64/firefox/browser/omni.ja -appdir /usr/lib64/firefox/browser 8354 tab 4 root 12479 2648 0 16:57 pts/0 00:00:00 grep --color=auto firefox 5 [root@localhost ~]# kill 8354 6 [root@localhost ~]# kill 8429 7 bash: kill: (8429) - 没有那个进程 //这里是因为首先把父程序关闭了
与kill命令作用相似但是比kill更加好用的杀死进程的命令:killall
语法:#killall 进程名称
1 [root@localhost ~]# ps -ef|grep firefox 2 root 12808 1 45 17:01 ? 00:00:26 /usr/lib64/firefox/firefox 3 root 12904 12808 7 17:01 ? 00:00:02 /usr/lib64/firefox/plugin-container -greomni /usr/lib64/firefox/omni.ja -appomni /usr/lib64/firefox/browser/omni.ja -appdir /usr/lib64/firefox/browser 12808 tab 4 root 12978 2648 0 17:02 pts/0 00:00:00 grep --color=auto firefox 5 您在 /var/spool/mail/root 中有新邮件 6 [root@localhost ~]# killall firefox //已经关闭
1.10 ifconfig指令(重点)
作用:用于操作网卡相关的指令。
语法:#ifconfig(获取网卡信息)
代码示例:
1 [root@localhost ~]# ifconfig 2 ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 3 ether 00:0c:29:43:fc:ce txqueuelen 1000 (Ethernet) 4 RX packets 8632 bytes 3374518 (3.2 MiB) 5 RX errors 0 dropped 0 overruns 0 frame 0 6 TX packets 2736 bytes 261009 (254.8 KiB) 7 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 8 9 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 10 inet 127.0.0.1 netmask 255.0.0.0 11 inet6 ::1 prefixlen 128 scopeid 0x10<host> 12 loop txqueuelen 1 (Local Loopback) 13 RX packets 1444 bytes 126420 (123.4 KiB) 14 RX errors 0 dropped 0 overruns 0 frame 0 15 TX packets 1444 bytes 126420 (123.4 KiB) 16 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 17 18 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 19 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 20 ether 52:54:00:26:c0:5c txqueuelen 1000 (Ethernet) 21 RX packets 0 bytes 0 (0.0 B) 22 RX errors 0 dropped 0 overruns 0 frame 0 23 TX packets 0 bytes 0 (0.0 B) 24 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Eth0表示Linux中的一个网卡,eth0是其名称。Lo(loop,本地回还网卡,其ip地址一般都是127.0.0.1)也是一个网卡名称。
注意:inet addr就是网卡的ip地址。
1.11 reboot指令
作用:重新启动计算机
语法1:#reboot
语法2:#reboot -w 模拟重启,但是不重启(只写关机与开机的日志信息)
1.12 shutdown指令
作用:关机
语法1:#shutdown -h now “关机提示” 或者 #shutdown -h 15:25 表示在某时刻关机
如果想要取消关机计划的话,则可以按照以下方式去尝试:
- 针对于centos7.x之前的版本:ctrl+c
- 针对于centos7.x(包含)之后的版本:#shutdown -c
注意:除了shutdown关机以外,还有以下几个关机命令:
#init 0
#halt
#poweroff
1.13 uptime指令
作用:输出计算机的持续在线时间(计算机从开机到现在运行的时间)
语法:#uptime
代码示例:
1 [root@localhost ~]# uptime 2 17:16:49 up 2:56, 2 users, load average: 0.00, 0.13, 0.31
1.14 uname指令
作用:获取计算机操作系统相关信息
语法1:#uname (获取操作系统的类型)
语法2:#uname -a (表示获取全部的系统信息(类型、全部主机名、内核版本、发布时间、开源计划))
代码示例:
1 [root@localhost ~]# uname 2 Linux 3 [root@localhost ~]# uname -a 4 Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
1.15 netstat -tnlp指令
作用:查看网络连接状态
语法:#netstat -tnlp
代码示例:
1 [root@localhost ~]# netstat -tnlp 2 Active Internet connections (only servers) 3 Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name 4 tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd 5 tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1433/dnsmasq 6 tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1030/sshd 7 tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1031/cupsd 8 tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1272/master 9 tcp6 0 0 :::111 :::* LISTEN 1/systemd 10 tcp6 0 0 :::22 :::* LISTEN 1030/sshd 11 tcp6 0 0 ::1:631 :::* LISTEN 1031/cupsd 12 tcp6 0 0 ::1:25 :::* LISTEN 1272/master
选项说明:
- -t:表示只列出tcp协议的连接;
- -n:表示将地址从字母组合转化成ip地址,将协议转化成端口号来显示;
- -l:表示过滤出“state(状态)”列中其值为LISTEN(监听)的连接;
- -p:表示显示发起连接的进程pid和进程名称;
1.16 man指令
作用:manual,手册(包含了Linux中全部命令手册,英文)
语法:#man 命令 (退出按下q键)
代码示例:
1 [root@localhost ~]# man 2 您需要什么手册页? 3 [root@localhost ~]# man cp