TUE.操作系统及 Shell 命令
操作系统相关
在 GRUB 界面按 e 进入内核
rw init=/sysroot/bin/sh
ctrl + x
chroot /sysroot
passwd (root)
密码
密码
touch /.autorelabel
grub2-setpassword
Enter password:
Cofurm password:
reboot
1. 调整启动顺序,使用光盘启动
2. Troubleshooting
3. Rescue a CentOS Linux System
4. 1)continue: 救援模式程序会自动查找系统中已有的文件系统,并可读写挂载到 /mnt/sysimage 目录下
2)Read-Only:会以只读的方式挂载已有的文件系统。
3)Skip to shell: 手动挂载
5. chroot /mnt/sysimage/
6. passwd root
vi /etc/sysconfig/selinux
将 SELINUX=enforcing 修改为 SELINUX=disabled
基本命令
Shell 介绍
- POSIX
- 可移植操作系统接口,是操作系统为提供的接口标准
- 不同操作系统内核为同一功能提供的系统调用(函数)是不同的,因为我们可以通过定义 POSIX 标准,Linux 和 Windows 实现基于 POSIX 标准,提供同样的接口
Shell 交互式环境
[root@xxx ~]
[root@xxx ~]$ $号代表普通用户对应的命令行
root --> 当前登录的用户
@ --> 分隔符
xxx --> 主机名
~ --> 当前所在的路径
useradd 用户名
cd 文件路径
pwd
passwd 用户名
echo "123" | passwd egon --stdin
Shell 语法及命令
1. 命令 + 选项 + 参数
ls -l /boot
2. 命令 + 选项/参数
ls -l or /boot
3. 命令
ls
时间
date
date "+%F"
date "+%Y-%m-%d"
date "+%H:%M:%S"
date -s "2022-06-22 18:18:18"
hwclock
hwclock -w
hwclock -s
yum install ntpdate -y
ntpdate ntp1.aliyun.com
timedatectl set-ntp true
timedatectl list-timezones
timedatectl set-timezone "Asia/Shanghai"
查看文件内容
cat
cat /etc/sysconfig/network-scripts/ifcfg-eth0
cat /etc/readhat-release
uname
uname -a
uname -r
uname -m
重启
shutdown -r 0
shutdown -r now
init 6
reboot
shutdown -r 10
shutdown -r 12:30
shutdown -h 0
shutdown -h now
init 0
poweroff
shutdown -c
退出
exit
logout
ctrl + d
Bash 解释器交互式环境的特性
- 命令和文件自动补全: Tab 只能补全命令和文件
- 快捷键
Ctrl + c 终止前台运行程序
Ctrl + d 退出 == exit
Ctrl + l 清屏
Ctrl + a 光标移动命令行的最前端
Ctrl + e 光标移到命令行的最后端
Ctrl + r 搜索历史命令,利用关键词
Alt + . 引用上一个命令的最后一个参数,等价与!$
- 历史命令
/root/.bash_history
history
history -c
! + 历史命令编号
! + 字符串
1) alias xxx="cat /etc/sysconfig/network-scripts/ifcig-eth0"
2) vim /etc/profile(系统文件)
3) 写入 alias xxx="cat /etc/sysconfig/network-scripts/ifcig-eth0" 并保存
PS: 直接使用命令的原始路径可以规避命令别名
which 命令名
"""
which rm
alias rm='rm -i' # 经过修饰的系统 rm,带有提醒功能
/user/bin/rm
/user/bin/rm 文件名 # 即原始 rm,只删除,不再带提醒功能
"""
\rm
unalias rm