二、回忆redhat各种基本命令

本文详细介绍Linux系统中常见的基本命令及其使用方法,包括文件信息查看、日期与日历显示、计算器模式、因式分解、内核版本查看等。同时,深入讲解查看文件的多种方式,如cat、more、less及head、tail命令的区别与应用,以及如何利用快捷键提升操作效率。此外,还介绍了用户切换、权限管理、系统关机与重启等实用技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以此根目录中所有文件作为演示,蓝色为文件夹,白色为文件。在这里插入图片描述

一、常见基本命令

1、file 文件名 //功能:查看文件信息

[root@localhost ~]# file hello //查看文件信息
hello: very short file (no magic)
[root@localhost ~]# file anaconda-ks.cfg
anaconda-ks.cfg: ASCII text

2、date //功能:显示当前时间

[root@localhost ~]# date //显示当前时间
Sun Sep  6 16:13:37 EDT 2020

3、cal //功能:显示当前月日历

[root@localhost ~]#  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 
[root@localhost ~]# 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   
[root@localhost ~]# 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 //功能:进入计算器模式

[root@localhost ~]# 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 //功能因式分解

[root@localhost ~]# factor //因式分解
4234345
4234345: 5 846869

12
12: 2 2 3
^C  //按ctrl+c退出因式分解模式

6、uname -r //功能:查看内核版本

[root@localhost ~]# uname -r //查看内核版本
4.18.0-80.el8.x86_64

7、history //功能:查看历史输入记录,最多可查看前1000条

[root@localhost ~]# 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
[root@localhost ~]# !30  //执行历史输入记录中第三十行
systemctl is-active sshd
active

[root@localhost ~]# !! //执行上一条历史记录。因为上一条写的是执行第三十条记录,所以执行结果与上一条执行结果相同
systemctl is-active sshd
active
[root@localhost ~]# history -c //清除历史记录
[root@localhost ~]# histroy
bash: histroy: command not found...
Failed to search for file: Cannot update read-only repo

二、 关于查看文件的命令

1、cat/more/less 文件名 //功能:都可以查看文件内容
区别在于:
cat //一次性显示所有内容

[root@localhost ~]# 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
[root@localhost ~]#

more //显示部分内容且不能向上翻页,并在最下面显示当前内容占全部内容的百分之多少

[root@localhost ~]# 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
[root@localhost ~]#

less // 显示部分内容,可,以向上翻页并不显示占全部内容的百分之多少

[root@localhost ~]# 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
[root@localhost ~]# less  anaconda-ks.cfg  
[root@localhost ~]# 

2、head 文件名/tail 文件名 //功能:默认查看文件头十行或尾十行

[root@localhost ~]# 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
[root@localhost ~]# 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 //设置查看文件开始行数,看文件尾也可以用

[root@localhost ~]# 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、查看文件大小属性

[root@localhost ~]# pwd anaconda-ks.cfg n-3 //pwd查看文件路径
[root@localhost ~]# 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 - 其他用户名 //无需密码

[root@localhost ~]# su - cami //root切换至其他用户
[cami@localhost ~]$ 

2、其他用户进入root
su - //有秘密

[cami@localhost ~]$ su -
Password: 
[root@localhost ~]# 

3、root刚刚控制进入一般用户再返回
exit //无需密码

[root@localhost ~]# su - cami
[cami@localhost ~]$ exit
logout
[root@localhost ~]# 

4、root用户可以创建、删除、更改用户密码 :
useradd user1 //创建user1
userdel user1//删除user1
passwd user1//给user1密码设置,若不用满足系统要求的复杂性,则需重复输入

[root@localhost ~]# useradd user1//创建user1
[root@localhost ~]# 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.
[root@localhost ~]# userdel user1//删除user1
[root@localhost ~]# su - user1//user1不存在
su: user user1 does not exist

5、普通用户给自己设置密码,需要满足系统要求的密码复杂性

[user1@localhost ~]$ passwd //普通用户给自己设置密码
Changing password for user user1.
Current password: 
Current Password: 
passwd: Authentication token manipulation error//密码不满足复杂性操作失败

五、关机、重启快捷键

init 0 关机
在这里插入图片描述

init 5 切换图形化界面

[user1@localhost ~]$ init 5

在这里插入图片描述
在这里插入图片描述

init 6 重启
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值