二、回忆redhat各种基本命令
二、回忆redhat各种基本命令
这里写目录标题一、常见基本命令
二、 关于查看文件的命令
三、快捷键
四、用户切换
五、关机、重启快捷键
以此根目录中所有文件作为演示,蓝色为文件夹,白色为文件。
一、常见基本命令
1、file 文件名 //功能:查看文件信息
[[email protected] ~]# file hello //查看文件信息
hello: very short file (no magic)
[[email protected] ~]# file anaconda-ks.cfg
anaconda-ks.cfg: ASCII text
2、date //功能:显示当前时间
[[email protected] ~]# date //显示当前时间
Sun Sep 6 16:13:37 EDT 2020
3、cal //功能:显示当前月日历
[[email protected] ~]# cal
September 2020
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
[[email protected] ~]# cal -3 //显式当前月份与前后共三个月份日历
August 2020 September 2020 October 2020
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 1 2 3 4 5 1 2 3
2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
30 31
[[email protected] ~]# cal 2020 //显示2020全年日历
2020
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5 6 7
5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14
12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21
19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28
26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 2 1 2 3 4 5 6
5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
26 27 28 29 30 24 25 26 27 28 29 30 28 29 30
31
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5
5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12
12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19
19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26
26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30
30 31
October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 1 2 3 4 5 6 7 1 2 3 4 5
4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12
11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19
18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26
25 26 27 28 29 30 31 29 30 27 28 29 30 31
4、bc //功能:进入计算器模式
[[email protected] ~]# bc //功能:计算器模式
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
1+1
2
234*23
5382
2324-221
2103
434223/231
1879
434223%231
174
^C //按ctrl+c退出计算器模式
(interrupt) Exiting bc.
5、factor //功能因式分解
[[email protected] ~]# factor //因式分解
4234345
4234345: 5 846869
12
12: 2 2 3
^C //按ctrl+c退出因式分解模式
6、uname -r //功能:查看内核版本
[[email protected] ~]# uname -r //查看内核版本
4.18.0-80.el8.x86_64
7、history //功能:查看历史输入记录,最多可查看前1000条
[[email protected] ~]# history //查看历史输入记录
1 ld
2 cd rot
3 cd root
4 cd /
5 ls
6 ls -a
7 top
8 which drop_caches
9 which dcache
10 which cache
11 cd /pro
12 firefox
13 firefox &
14 kill -9 %1
15 firefox &
16 jobs
17 kill -19 %2
18 fg %2
19 bg %2
20 systemctl list-unit-files
[[email protected] ~]# !30 //执行历史输入记录中第三十行
systemctl is-active sshd
active
[[email protected] ~]# !! //执行上一条历史记录。因为上一条写的是执行第三十条记录,所以执行结果与上一条执行结果相同
systemctl is-active sshd
active
[[email protected] ~]# history -c //清除历史记录
[[email protected] ~]# histroy
bash: histroy: command not found...
Failed to search for file: Cannot update read-only repo
二、 关于查看文件的命令
1、cat/more/less 文件名 //功能:都可以查看文件内容
区别在于:
cat //一次性显示所有内容
[[email protected] ~]# cat anaconda-ks.cfg //cat一次性显示所有内容
#version=RHEL8
ignoredisk --only-use=sda
# Partition clearing information
clearpart --none --initlabel
# Use graphical install
graphical
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
[[email protected] ~]#
more //显示部分内容且不能向上翻页,并在最下面显示当前内容占全部内容的百分之多少
[[email protected] ~]# more anaconda-ks.cfg //more显示部分内容
#version=RHEL8
ignoredisk --only-use=sda
# Partition clearing information
clearpart --none --initlabel
# Use graphical install
graphical
firstboot --enable
-- more--(40%)
按空格键继续显示,直至结束
%packages
@^graphical-server-environment
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
--More--(85%)
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
[[email protected] ~]#
less // 显示部分内容,可,以向上翻页并不显示占全部内容的百分之多少
[[email protected] ~]# less anaconda-ks.cfg //less显示部分内容
#version=RHEL8
ignoredisk --only-use=sda
# Partition clearing information
clearpart --none --initlabel
# Use graphical install
graphical
firstboot --enable
按空格键继续显示,可随时结束阅读结束阅读时需要按“:q”
firstboot --enable
:q
[[email protected] ~]# less anaconda-ks.cfg
[[email protected] ~]#
2、head 文件名/tail 文件名 //功能:默认查看文件头十行或尾十行
[[email protected] ~]# head anaconda-ks.cfg //默认查看文件头十行
#version=RHEL8
ignoredisk --only-use=sda
# Partition clearing information
clearpart --none --initlabel
# Use graphical install
graphical
repo --name="AppStream" --baseurl=file:///run/install/repo/AppStream
# Use CDROM installation media
cdrom
# Keyboard layouts
[[email protected] ~]# tail anaconda-ks.cfg //默认查看文件尾十行
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
head 文件名 -n 3 //设置查看文件开始行数,看文件尾也可以用
[[email protected] ~]# tail anaconda-ks.cfg -n 3 //查看文件尾三行
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
3、查看文件大小属性
[[email protected] ~]# pwd anaconda-ks.cfg n-3 //pwd查看文件路径
[[email protected] ~]# wc /root/anaconda-ks.cfg //wc 文件路径/文件名查看文件大小属性
//*文本行数* *文本字数* *文本字符数* *文本路径*
50 149 1664 /root/anaconda-ks.cfg
三、快捷键
ctrl+a/home 跳到命令行开头
ctrl+e/end 跳到命令行结尾
ctrl+C 结束当前错误命令行
ctrl+L 清屏
四、用户切换
1、root用户切换至其他用户
su - 其他用户名 //无需密码
[[email protected] ~]# su - cami //root切换至其他用户
[[email protected] ~]$
2、其他用户进入root
su - //有秘密
[[email protected] ~]$ su -
Password:
[[email protected] ~]#
3、root刚刚控制进入一般用户再返回
exit //无需密码
[[email protected] ~]# su - cami
[[email protected] ~]$ exit
logout
[[email protected] ~]#
4、root用户可以创建、删除、更改用户密码 :
useradd user1 //创建user1
userdel user1//删除user1
passwd user1//给user1密码设置,若不用满足系统要求的复杂性,则需重复输入
[[email protected] ~]# useradd user1//创建user1
[[email protected] ~]# passwd user1//给user1密码设置
Changing password for user user1.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[[email protected] ~]# userdel user1//删除user1
[[email protected] ~]# su - user1//user1不存在
su: user user1 does not exist
5、普通用户给自己设置密码,需要满足系统要求的密码复杂性
[[email protected] ~]$ passwd //普通用户给自己设置密码
Changing password for user user1.
Current password:
Current Password:
passwd: Authentication token manipulation error//密码不满足复杂性操作失败
五、关机、重启快捷键
init 0 关机
init 5 切换图形化界面
[[email protected] ~]$ init 5
init 6 重启
二、回忆redhat各种基本命令相关教程