- shutdown 关机或重启
shutdown+选项+ITME的用法
- shutdown -r +3 3分钟后重启
- shutdown -h +3 3分钟后关机
- shutdown -c 取消shutdown执行的命令
[root@CentOS7 ~]# shutdown -r +3
Shutdown scheduled for Thu 2019-03-21 15:24:09 CST, use 'shutdown -c' to cancel.
[root@CentOS7 ~]#
Broadcast message from root@CentOS7.localdomain (Thu 2019-03-21 15:21:09 CST):
The system is going down for reboot at Thu 2019-03-21 15:24:09 CST!
date
Thu Mar 21 15:21:11 CST 2019
[root@CentOS7 ~]# shutdown -c
Broadcast message from root@CentOS7.localdomain (Thu 2019-03-21 15:21:21 CST):
The system shutdown has been cancelled at Thu 2019-03-21 15:22:21 CST!
- 用户登录信息查看命令:
- whoami 显示当前登录有效用户
- who 系统当前所有的登录会话
- w 系统当前所有的登录会话及所有操作
[root@CentOS7 ~]# whoami
root
[root@CentOS7 ~]# who
lqx :0 2019-03-21 14:54 (:0)
lqx pts/0 2019-03-21 15:11 (:0)
root pts/1 2019-03-21 15:13 (192.168.152.1)
[root@CentOS7 ~]# w
15:24:55 up 31 min, 3 users, load average: 0.07, 0.03, 0.11
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
lqx :0 :0 14:54 ?xdm? 1:35 0.55s /usr/libexec/gnome-sessio
lqx pts/0 :0 15:11 12:31 0.20s 0.20s bash
root pts/1 192.168.152.1 15:13 7.00s 0.18s 0.07s w
- screen 实现远程协助
- 查看screen是否安装,输入命令df里如果无光盘,则使用mount /dev/sr0 /mnt命令挂载,mnt是专门充当挂载点的目录。
[root@CentOS7 ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 is write-protected, mounting read-only
[root@CentOS7 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 104806400 4263656 100542744 5% /
devtmpfs 915820 0 915820 0% /dev
tmpfs 931624 0 931624 0% /dev/shm
tmpfs 931624 10696 920928 2% /run
tmpfs 931624 0 931624 0% /sys/fs/cgroup
/dev/sda3 52403200 32992 52370208 1% /data
/dev/sda1 1038336 177948 860388 18% /boot
tmpfs 186328 24 186304 1% /run/user/1000
/dev/sr0 10491772 10491772 0 100% /mnt
tmpfs 186328 0 186328 0% /run/user/0
- 安装screen软件,输入命令 rpm -ivh /mnt/Packages/screen-4.1.0-0.25.20120314git3c2946.el7.x86_64.rpm即可
[root@CentOS7 ~]# rpm -ivh /mnt/Packages/screen-4.1.0-0.25.20120314git3c2946.el7.x86_64.rpm
warning: /mnt/Packages/screen-4.1.0-0.25.20120314git3c2946.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:screen-4.1.0-0.25.20120314git3c29################################# [100%]
- 连接同一台电脑的同一用户,需要被协助的需输入命令screen -S A (A可为任意名称,指回话的名称);同时协助者可通过screen -ls命令查看需要远程的对象,输入screen -x A(A可为任意名称,指回话的名称)加入回话。
- 输入screen命令,在此界面中输入的命令及时窗口崩溃,重新连接后仍在继续执行。
- screen -r 恢复会话
- 快捷键Ctrl+a+b 临时退出会话
- echo 显示字符
- echo -n 不换行
- echo -e 显示特殊字符
如\c 最后不加上换行符号;给hello加颜色及特殊闪烁 '\033[43;31;5mhello\033[0m’
[root@CentOS7 ~]# echo hello
hello
[root@CentOS7 ~]# echo -n
[root@CentOS7 ~]# echo -n hello
hello[root@CentOS7 ~]# echo -e '\033[43;31;5mhello\033[0m'
hello
- echo 默认显示变量
加双引号,识别变量;加单引号,无视变量,以字符显示;加反向单引号,以命令识别。
[root@CentOS7 ~]# echo $PS1
[\u@\h \W]\$
[root@CentOS7 ~]# echo "echo $PS1"
echo [\u@\h \W]\$
[root@CentOS7 ~]# echo 'echo $PS1'
echo $PS1
[root@CentOS7 ~]# echo `echo $PS1`
[\u@\h \W]\$
- { } 花括号表示显示的范围
利用花括号配合命令可以同时查看或创建多个文件
[root@CentOS7 ~]# echo {0..10}
0 1 2 3 4 5 6 7 8 9 10
[root@CentOS7 ~]# echo {0..10}{txt,log}
0txt 0log 1txt 1log 2txt 2log 3txt 3log 4txt 4log 5txt 5log 6txt 6log 7txt 7log 8txt 8log 9txt 9log 10txt 10log
[root@CentOS7 ~]# touch /data/file{1..10}.txt
[root@CentOS7 ~]# ls /data
file10.txt file2.txt file4.txt file6.txt file8.txt
file1.txt file3.txt file5.txt file7.txt file9.txt
[root@CentOS7 ~]# echo {000..20..2}
000 002 004 006 008 010 012 014 016 018 020
- man ascii 查看ASCII表,按q退出。
- history 查看以前执行过的命令,记录下的命令会保存在 ~/.bash_history文件中
- !!跟上history查询过的命令编码,可直接执行命令。
- !-*( *=数字),可执行倒数第某条命令。
- 快捷键Ctrl+r 在历史命令中搜索命令
- 快捷键Ctrl+g 从历史搜索模式退出
- !$ 前一个命令最后一个参数(或ESC+. )
[root@CentOS7 ~]# ls -l anaconda-ks.cfg
-rw-------. 1 root root 1959 Mar 18 21:41 anaconda-ks.cfg
[root@CentOS7 ~]# cat !$
cat anaconda-ks.cfg
#version=DEVEL
# System authorization information
···
- history -c 清除当前内存历史,不清除之前存储过的历史记录
- whatis 查询命令的用户(cat后括号内的数字为章节的编号)
[root@CentOS7 ~]# whatis cat
cat (1) - concatenate files and print on the standard output
cat (1p) - concatenate and print files
- help 查询内部命令的帮助说明
[root@CentOS7 ~]# help exit
exit: exit [n]
Exit the shell.
Exits the shell with a status of N. If N is omitted, the exit status
is that of the last command executed.
- –help 查询外部命令的帮助说明,少数情况使用-h
[root@CentOS7 ~]# cat --help
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s), or standard input, to standard output.
-A, --show-all equivalent to -vET
-b, --number-nonblank number nonempty output lines, overrides -n
···
- man 提供命令帮助的文件,分章节存放;统称为Linux手册。
帮助手册中的段落说明:
NAME 名称及简要说明
SYNOPSIS 用法格式说明
[] 可选内容;<>必选内容;a|b二选一;{}分组;…同一内容可出现多次
DESCRIPTION 详细说明;OPTIONS 选项说明;EXAMPLES示例;FILES相关文件;AUTHOR作者;COPYRIGHT版本信息;REPORTING BUGS bug信息;SEE ALSO其他帮助参考
- 1:用户命令;2:系统调用;3:C库调用
- 4:设备文件及特殊文件;5:配置文件格式;6:游戏
- 7:杂项;8:管理类的命令;9:Linux内核API
(注:直接使用man+命令查询,默认查询章节号小的帮助文件,如需要指定某个章节,则需输入man+章节序号+命令)
- 进入man帮助里后,可用 / 或 ? 进行搜索, / 往下搜, ? 往上搜。 / 搜索状态,n :往下搜,N :往上搜, ? 则反之。Q :退出。
- passwd 修改用户登陆口令(如果是以root权限登陆,使用passwd后跟需修改的用户名及可修改其口令