二、开关机引导与进程管理
2.1man
获得命令的帮助手册,如 man cp;按 q 键退出
2.2 su
切换用户,如 su – root;“-”表示改变用户的环境变量
从低到高(等级)需要输密码,从高到低(等级)不需要。
who 显示系统中登录的用户
2.3 w
显示登录用户的详细信息
[root@joyRHLinux8 ~]# w
20:36:58 up 2:11, 2 users, load average: 0.01, 0.00, 0.12
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.5.22 20:19 1.00s 0.08s 0.02s w
joy tty2 tty2 18:42 2:11m 23.95s 0.14s /usr/libexec/tracker-miner-fs
[root@joyRHLinux8 ~]# w root
20:37:53 up 2:12, 2 users, load average: 0.08, 0.02, 0.11
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.5.22 20:19 1.00s 0.07s 0.01s w root
last 查看最近登录系统的用户信息
date 系统日期时间的设定,一般要结合参数-s 使用
uname 查看系统的版本,如 uname -R
2.4 reboot
重启计算机,如 reboot; shutdown – r now 停止服务后重启
[root@joyRHLinux8 ~]# reboot --help
reboot [OPTIONS...] [ARG]
Reboot the system.
--help Show this help
--halt Halt the machine
-p --poweroff Switch off the machine
--reboot Reboot the machine
-f --force Force immediate halt/power-off/reboot
-w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
-d --no-wtmp Don't write wtmp record
--no-wall Don't send wall message before halt/power-off/reboot
2.5 shutdown
关闭计算机;如 shutdown – h now 表示停止服务后再关闭
[root@joyRHLinux8 ~]# shutdown -r 1
Shutdown scheduled for Mon 2021-11-22 20:34:27 CST, use 'shutdown -c' to cancel.
取消关机命令
shutdown -c
--help显示帮助
[root@joyRHLinux8 ~]# shutdown --help
shutdown [OPTIONS...] [TIME] [WALL...]
Shut down the system.
--help Show this help
-H --halt Halt the machine
-P --poweroff Power-off the machine
-r --reboot Reboot the machine
-h Equivalent to --poweroff, overridden by --halt
-k Don't halt/power-off/reboot, just send warnings
--no-wall Don't send wall message before halt/power-off/reboot
-c Cancel a pending shutdown
2.6 free
查看内存和 swap 分区情况
2.7 ps
显示进程信息,参数-ux 为当前用户的进程;参数-aux 为所有用户的进程;
ps -aux |more
执行后结果如下:
ps -A
ps -u root
参数-ef 为系统所有进程信息
ps -aux --sort=-pcpu
查看单个进程
uptime 显示当前时间,系统开机运转时间,连线数,最近 1、5、15 分钟的系统负载。
2.8 top
查看系统 CPU、内存等使用情况
2.9 kill
删除某个进程,
进程号可用 ps 命令获得,如 kill -9 22859
[root@joyRHLinux8 ~]# kill -9 22859
帮助命令提示
[root@joyRHLinux8 ~]# kill --help
kill: kill [-s 信号声明 | -n 信号编号 | -信号声明] 进程号 | 任务声明 ... 或 kill -l [信号声明]
Send a signal to a job.
Send the processes identified by PID or JOBSPEC the signal named by
SIGSPEC or SIGNUM. If neither SIGSPEC nor SIGNUM is present, then
SIGTERM is assumed.
Options:
-s sig SIG is a signal name
-n sig SIG is a signal number
-l list the signal names; if arguments follow `-l' they are
assumed to be signal numbers for which names should be listed
-L synonym for -l
Kill is a shell builtin for two reasons: it allows job IDs to be used
instead of process IDs, and allows processes to be killed if the limit
on processes that you can create is reached.
Exit Status:
Returns success unless an invalid option is given or an error occurs.
[root@joyRHLinux8 ~]# kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
2.10 vmstat
查看内存使用情况
2.11 nohup
使进程在用户退出登陆后仍旧继续执行
[root@joyRHLinux8 ~]# nohup top &
[1] 22963
jobs 查看被挂起和后台运行的进程
Ctrl+Z 进程挂起
Ctrl+C 进程终止
fg 进程恢复到前台继续执行
bg 进程恢复到后台继续执行
service 系统服务启停操作(RHEL7 之前)
Systemctl 系统服务启停操作(RHEL7 之后)
info 与 man
没有太大的区别,只不过是信息的呈现方式不太一样,并且在 UNIX 系统中并没有这个命令。
whatis 获取相关文件简短的信息
locate 寻找文件或目录,最好用于快速定位系统命令,配置文件等
which 文件搜索命令
find 查找文件或目录,任何文件皆可,如图片,压缩包等
grep 在文件中搜寻字串匹配的行并输出
help 查看 Shell 内置命令的文件帮助