RHCSA 基础2

目录

#01、创建以上目录和文件结构,并将/yasuo目录拷贝4份到/目录下

#02、使用gzip默认不保留源文件,压缩hostname到当前工作目录

#03、使用bzip2默认不保留源文件,压缩hostname02到当前工作目录

#04、使用xz默认不保留源文件,压缩passwd到当前工作目录

#05、不保留源文件解压缩hostname.gz hostname02.gz  passwd.xz

#06、tar打包和解包的格式

#07、打包并压缩/yasuo/dir1,并解包

#08、查看系统合法shell

#09、查看系统发行版版本

#10、查看系统内核版本

#11、临时修改主机名

#12、查看系统指令的查找路径

#13、查看passwd指令的执行路径

#14、为/yasuo/ssh_config文件创建软链接/ssh_config.link到/mulu下

#15、创建目录/mulu1 ,重命名并移动/ssh_config.link

#16、找到你的根目录下的所有块设备文件

#17、将/etc/passwd和/etc/ssh/sshd_config文件复制到/root/etc/目录下

#18、复制/var/log/messages到/root目录下

#19、打包/root/messages和/root/etc/为/root/me.tar.bz2

#20、解压/root/me.tar.bz2

#22、找到/etc/passwd中有root信息的行内容

#25、真实案例:在公司网站日志文件如下【它会记录谁曾经在什么时间访问过它】:领导要求:查出访问我们公司网站排名第一的客户端ip地址,并且还要知道访问次数2023/06/17  07:50:56  10.0.0.1 Chrome2023/06/15  09:09:49  192.168.1.2 Chrome2023/05/11  20:54:31  10.0.0.1 Chromefirefox2023/04/13  01:22:42  192.168.1.2 firefox2023/03/10  17:19:10  10.0.0.2 Chrome2023/01/07  05:08:22  192.168.1.2 firefox

#30、创建目录/dir1,复制/etc/passwd文件到该目录

#31、将/dir1/passwd重命名为passwd.back

#32、列出目录/root和/aaaaa,将标准输出重定向到ok.file,标准错误输出重定向到erro.file

#33、列出目录/root和/aaaaa,将标准输出和标准错误输出都丢掉

#34、在/根目录下创建一个haha目录

#35、在/根目录下创建xixi文件

#36、往xixi文件里面写'wo shi xixi ^=^'

#37、为文件xixi在/目录下创建软链接xixi.link

#38、将xixi.link重命名为xixi.link2.0

#39、说说Linux系统中里/etc  /dev  目录

#40、过滤/etc/ssh/sshd_conf不显示注释行和空行

#41、在/opt目录下创建一个临时目录tmp;

#42、在临时目录/opt/tmp下创建一个文件,文件名为a.txt;

使用vim编辑器完成以下步骤:#44、应用vim命令在/tmp文件夹下创建文件,文件名newfile。在newfile首行输入日期时间

#45、将/boot/grub2/grub.cfg文档的内容读入到newfile文档中(在日期的下一行即第2行)

#46 、查找newfile文档中包含#号字符的行,将整行删除:g/#/d

#47、 开启VI的行号提示功能 

#48、在当前目录及子目录中,查找文件名字以大写字母开头的txt文件

#49、在/etc及其子目录中,查找文件内容以host开头的文件

#50、在$HOME目录及其子目录中,查找所有文件

#51、查找文件/etc/passwd中包含字符串 /bin/bash 的所有行。将所有这些行的副本按原始顺序放在文件/root/files 中

#52、将整个 /etc 目录下的文件全部打包并用 gzip 压缩成/back/etcback.tar.gz


#01、创建以上目录和文件结构,并将/yasuo目录拷贝4份到/目录下

[root@localhost ~]# ls /yasuo               // 先检查是否有yasuo目录
ls: 无法访问 '/yasuo': 没有那个文件或目录
[root@localhost ~]# mkdir -p /yasuo/dir1     // 递归创建目录
[root@localhost ~]# cp /etc/hostname   /yasuo/dir1/        // 拷贝文件
[root@localhost ~]# cp /etc/hostname   /yasuo/dir1/hostname02
[root@localhost ~]# cp /etc/passwd   /yasuo/dir1/
[root@localhost ~]# cp /etc/ssh/ssh_config   /yasuo/dir1/
[root@localhost ~]# cp /etc/ssh/ssh_config   /yasuo/dir1/sshd
[root@localhost ~]# cp /yasuo/dir1/*   /yasuo/          
[root@localhost ~]# tree /yasuo

/yasuo
├── dir1
│   ├── hostname
│   ├── hostname02
│   ├── passwd
│   ├── ssh_config
│   └── sshd
├── hostname
├── hostname02
├── passwd
├── ssh_config
└── sshd

#02、使用gzip默认不保留源文件,压缩hostname到当前工作目录

root@hahaha ~]# gzip /yasuo/dir1/hostname

[root@hahaha ~]# tree /yasuo/dir1
/yasuo/dir1
├── hostname02
├── hostname.gz
├── passwd
├── ssh_config
└── sshd

#03、使用bzip2默认不保留源文件,压缩hostname02到当前工作目录

[root@hahaha ~]# bzip2 /yasuo/dir1/hostname02

#04、使用xz默认不保留源文件,压缩passwd到当前工作目录

[root@hahaha ~]# xz /yasuo/dir1/passwd 
[root@hahaha ~]# tree /yasuo/dir1
/yasuo/dir1
├── hostname02.bz2
├── hostname.gz
├── passwd.xz
├── ssh_config
└── sshd

#05、不保留源文件解压缩hostname.gz hostname02.gz  passwd.xz

[root@hahaha ~]# gunzip /yasuo/dir1/hostname.gz 
[root@hahaha ~]# bunzip2 /yasuo/dir1/hostname02.bz2 
[root@hahaha ~]# unxz /yasuo/dir1/passwd.xz 
[root@hahaha ~]# tree /yasuo/dir1
/yasuo/dir1
├── hostname
├── hostname02
├── passwd
├── ssh_config
└── sshd
 

#06、tar打包和解包的格式

 基本格式:tar  -cvf  目标. tar源文件或目录

-c:表示创建新的归档文件。

-v:表示显示详细信息,即在打包过程中显示正在处理的文件。

-f:指定归档文件名。

#07、打包并压缩/yasuo/dir1,并解包

[root@hahaha ~]# tar -cavf /yasuo/dir1.tar.gz /yasuo/     打包到/yasuo目录下

[root@hahaha ~]# tree /yasuo/
/yasuo/
├── dir1
│   ├── hostname
│   ├── hostname02
│   ├── passwd
│   ├── ssh_config
│   └── sshd
├── dir1.tar.gz
├── hostname
├── hostname02
├── passwd
├── ssh_config
└── sshd

[root@hahaha ~]# mkdir  /yasuo/dir2
[root@hahaha ~]# tar  -xf  /yasuo/dir1.tar.gz -C  /yasuo/dir2       #将/yasuo/dir1.tar.gz指定解压至/yasuo/dir2 
[root@hahaha ~]# tree /yasuo/
/yasuo/
├── dir1
│   ├── hostname
│   ├── hostname02
│   ├── passwd
│   ├── ssh_config
│   └── sshd
├── dir1.tar.gz
├── dir2
│   └── yasuo
│       ├── dir1
│       │   ├── hostname
│       │   ├── hostname02
│       │   ├── passwd
│       │   ├── ssh_config
│       │   └── sshd
│       ├── hostname
│       ├── hostname02
│       ├── passwd
│       ├── ssh_config
│       └── sshd
├── hostname
├── hostname02
├── passwd
├── ssh_config
└── sshd

#08、查看系统合法shell

[root@localhost ~]#  cat /etc/shells

/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bas

#09、查看系统发行版版本

[root@localhost ~]# cat  /etc/redhat-release
Red Hat Enterprise Linux release 9.3 (Plow)

#10、查看系统内核版本

[root@localhost ~]# uname  -r
5.14.0-362.8.1.el9_3.x86_64

#11、临时修改主机名

[root@localhost ~]# hostname haha   // 临时修改

[root@localhost ~]# hostnamectl  hostname haha   // 永久修改

#12、查看系统指令的查找路径

which  [选项]  [命令名称或别名]

比如:

[root@hahaha ~]# which ls

/usr/bin/ls

#13、查看passwd指令的执行路径

[root@hahaha ~]# which passwd 
/usr/bin/passwd

#14、为/yasuo/ssh_config文件创建软链接/ssh_config.link到/mulu下

[root@hahaha ~]# mkdir  /mulu                 // 创建目录
[root@hahaha ~]# ln -s /yasuo/ssh_config  /mulu/ssh_config.link  // 创建软连接
[root@hahaha ~]# ll -d /mulu/ssh_config.link        // 查看
lrwxrwxrwx. 1 root root 17  8月  3 15:14 /mulu/ssh_config.link -> /yasuo/ssh_config

#15、创建目录/mulu1 ,重命名并移动/ssh_config.link

[root@hahaha ~]# mkdir  /mulu1

[root@hahaha ~]# mv /mulu /yasuo/mulu1 
[root@hahaha ~]# ls /yasuo/mulu1
root  ssh_config.link

#16、找到你的根目录下的所有块设备文件

[root@hahaha ~]# find / -type b
/dev/dm-1
/dev/dm-0
/dev/sr0
/dev/nvme0n1p3
/dev/nvme0n1p2
/dev/nvme0n1p1
/dev/nvme0n1
/run/user/0/systemd/inaccessible/blk
/run/systemd/inaccessible/blk

#17、将/etc/passwd和/etc/ssh/sshd_config文件复制到/root/etc/目录下

[root@hahaha ~]# cp /etc/passwd /root/etc/
cp: 无法创建普通文件'/root/etc/': 没有那个文件或目录
[root@hahaha ~]# mkdir -p /root/etc
[root@hahaha ~]# ls /root/etc      # 新创建的/root/etc内没有任何文件
[root@hahaha ~]# 
[root@hahaha ~]# cp /etc/passwd  /root/etc/
[root@hahaha ~]# cp /etc/ssh/ssh_config  /root/etc/
[root@hahaha ~]# ls /root/etc
passwd  ssh_config

#18、复制/var/log/messages到/root目录下

[root@hahaha ~]# cp  /var/log/messages  /root
[root@hahaha ~]# ls /root
dir2  erro.file  etc  haha  messages  ok.file  xixi  yasuo  yasuo_dir1.tar
 

#19、打包/root/messages和/root/etc/为/root/me.tar.bz2

[root@hahaha ~]# tar -cavf /root/me.tar.bz2 /root/messages 
[root@hahaha ~]# tar -cavf /root/me.tar.bz2 /root/etc 
[root@hahaha ~]# ll /root/me.tar.bz2 
-rw-r--r--. 1 root root 2011  8月  3 19:17 /root/me.tar.bz2

#20、解压/root/me.tar.bz2

[root@hahaha ~]# tar -xf /root/me.tar.bz2 -C /dir3/

#22、找到/etc/passwd中有root信息的行内容

[root@hahaha /]# grep "root" /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin

#25、真实案例:在公司网站日志文件如下【它会记录谁曾经在什么时间访问过它】:领导要求:查出访问我们公司网站排名第一的客户端ip地址,并且还要知道访问次数
2023/06/17  07:50:56  10.0.0.1 Chrome
2023/06/15  09:09:49  192.168.1.2 Chrome
2023/05/11  20:54:31  10.0.0.1 Chromefirefox
2023/04/13  01:22:42  192.168.1.2 firefox
2023/03/10  17:19:10  10.0.0.2 Chrome
2023/01/07  05:08:22  192.168.1.2 firefox

 [root@hahaha ~]# cut  -d  " "  -f  5  /log  |  sort  | uniq -c  |  sort 
      1 10.0.0.2
      2 10.0.0.1
      3 192.168.1.2

#30、创建目录/dir1,复制/etc/passwd文件到该目录

[root@hahaha ~]# mkdir /dir1
[root@hahaha ~]# cp /etc/passwd  /dir1

#31、将/dir1/passwd重命名为passwd.back

[root@hahaha ~]# mv /dir1/passwd /dir1/passwd.back

[root@hahaha ~]# ls /passwd
ls: 无法访问 '/passwd': 没有那个文件或目录
[root@hahaha ~]# ls /passwd.back 
/passwd.back

#32、列出目录/root和/aaaaa,将标准输出重定向到ok.file,标准错误输出重定向到erro.file

root@hahaha ~]#  ls -l /root  /aaaaa   1> /root/ok.file  2>/root/erro.file

root@hahaha ~]# ls -l /root /aaaaa
ls: 无法访问 '/aaaaa': 没有那个文件或目录
/root:
总用量 520
-rw-r--r--. 1 root root     55  8月  2 13:14 erro.file
drwxr-xr-x. 2 root root     38  8月  2 12:47 etc
-rw-------. 1 root root 522894  8月  2 12:54 messages
-rw-r--r--. 1 root root    236  8月  2 13:14 ok.file
[root@hahaha ~]# cat /root/ok.file
/root:
总用量 516
-rw-r--r--. 1 root root     55  8月  2 13:14 erro.file
drwxr-xr-x. 2 root root     38  8月  2 12:47 etc
-rw-------. 1 root root 522894  8月  2 12:54 messages
-rw-r--r--. 1 root root      0  8月  2 13:14 ok.file
[root@hahaha ~]# cat /root/erro.file
ls: 无法访问 '/aaaaa': 没有那个文件或目录

#33、列出目录/root和/aaaaa,将标准输出和标准错误输出都丢掉

[root@hahaha ~]# ls -l /root /aaaaa &>/dev/null

#34、在/根目录下创建一个haha目录

[root@hahaha ~]# mkdir /root/haha

[root@hahaha ~]# ll -d /root/haha
drwxr-xr-x. 2 root root 6  8月  2 13:21 /root/haha

#35、在/根目录下创建xixi文件

[root@hahaha ~]# touch /root/xixi
[root@hahaha ~]# ll /root/xixi
-rw-r--r--. 1 root root 0  8月  2 13:21 /root/xixi

#36、往xixi文件里面写'wo shi xixi ^=^'

[root@hahaha ~]# echo  'wo shi xixi ^=^'  >  /xixi
[root@hahaha ~]# cat /xixi
wo shi xixi ^=^

#37、为文件xixi在/目录下创建软链接xixi.link

[root@hahaha ~]# mkdir  /mulu
[root@hahaha ~]# ln -s  /root/xixi  /mulu/xixi.link
[root@hahaha ~]# ls -li  /mulu/xixi.link
18939533 lrwxrwxrwx. 1 root root 10  8月  2 13:28 /mulu/xixi.link -> /root/xixi

#38、将xixi.link重命名为xixi.link2.0

[root@hahaha ~]# mv  /mulu/xixi.link   /xixi.link2.0
[root@hahaha ~]# ls -li /xixi.link
ls: 无法访问 '/xixi.link': 没有那个文件或目录

[root@hahaha ~]# ls -li /xixi.link2.0
18939533 lrwxrwxrwx. 1 root root 10  8月  2 13:28 /xixi.link2.0 -> /root/xixi

#39、说说Linux系统中里/etc  /dev  目录

/etc 目录通常用于存储系统的配置文件。这些配置文件控制着系统的各种方面,包括网络配置、用户和组信息、服务的启动设置、软件包的配置等等。例如,passwd 文件包含用户账户信息,hosts 文件用于主机名解析,services 文件定义网络服务和端口等。

 

/dev 目录包含设备文件。设备文件用于与硬件设备进行交互,例如磁盘驱动器、打印机、终端等。这些设备文件提供了一种统一的接口,使得应用程序可以以相同的方式与不同类型的设备进行通信。设备文件可以分为字符设备文件和块设备文件。

#40、过滤/etc/ssh/sshd_conf不显示注释行和空行

[root@hahaha ~]# grep  -v  ^#  /etc/ssh/sshd_config  | grep -v ^$
Include /etc/ssh/sshd_config.d/*.conf
AuthorizedKeysFile    .ssh/authorized_keys
Subsystem    sftp    /usr/libexec/openssh/sftp-serve

#41、在/opt目录下创建一个临时目录tmp;

[root@hahaha ~]# sudo mkdir /opt/tmp

#42、在临时目录/opt/tmp下创建一个文件,文件名为a.txt;

[root@hahaha ~]# touch /opt/tmp/a.txt

使用vim编辑器完成以下步骤:
#44、应用vim命令在/tmp文件夹下创建文件,文件名newfile。在newfile首行输入日期时间

方法一:

[root@hahaha ~]# echo `date`
2024年 08月 03日 星期六 20:03:07 CST
[root@hahaha ~]# echo `date`> /tmp/newfile
[root@hahaha ~]# vim /tmp/newfile 

55375a7bd6a34b87b433c37b96bbb53a.png

方法二:

[root@hahaha ~]# touch /tmp/newfile

[root@hahaha ~]# vim /tmp/newfile   // 进入到vi编辑器,按“a 、i、o”进入插入模式即可输入日期时间

93fe7794f94a4e98b0f3f58df591794b.png

#45、将/boot/grub2/grub.cfg文档的内容读入到newfile文档中(在日期的下一行即第2行)

按esc键进入命令模式,再按“ : ”进入末行模式,用命令"r(空格)/(文件路径)"读入文档内容

:r /boot/grub2/grub.cfg

bc2638b48a44448ba04317eadbf3527c.png

#46 、查找newfile文档中包含#号字符的行,将整行删除
:g/#/d

‘ :’进入末行模式输入命令“g/搜索目标/d”

:g/#/d

1c10fb91801e4c619fbad49c85227626.png

8e42b167352946f6beaa81c3b3fe9026.png

#47、 开启VI的行号提示功能 

进入末行模式输入命令“set nu”开启行号提示功能

:set nu

532aeed884e7473682965d96d0e289c7.png

#48、在当前目录及子目录中,查找文件名字以大写字母开头的txt文件

[root@hahaha /]# find. -type f -name "[A-Z]*.txt"


#49、在/etc及其子目录中,查找文件内容以host开头的文件

[root@hahaha ~]# grep -r "^host" /etc
/etc/dnf/plugins/copr.conf:hostname = copr.fedorainfracloud.org
/etc/rhsm/rhsm.conf:hostname = subscription.rhsm.redhat.com
/etc/aliases:hostmaster:    root
/etc/services:hostname        101/tcp         hostnames       # usually from sri-nic
/etc/services:hostname        101/udp         hostnames       # usually from sri-nic
/etc/services:hostmon         5355/tcp        llmnr           # hostmon uses TCP (nocol)
/etc/services:hostmon         5355/udp        llmnr           # hostmon uses TCP (nocol)
/etc/rpc:hostperf    100107    na.hostperf
/etc/rpc:hostmem        100112    na.hostmem
/etc/rpc:hostif        100117    na.hostif
grep: /etc/selinux/targeted/policy/policy.33:匹配到二进制文件
/etc/nsswitch.conf.bak:hosts:      files dns myhostname
/etc/authselect/user-nsswitch.conf:hosts:      files dns myhostname
/etc/authselect/nsswitch.conf:hosts:      files dns myhostname
 

#50、在$HOME目录及其子目录中,查找所有文件

[root@hahaha etc]# find $HOME -type f

#51、查找文件/etc/passwd中包含字符串 /bin/bash 的所有行。将所有这些行的副本按原始顺序放在文件/root/files 中

[root@hahaha /]# grep "/bin/bash" /etc/passwd > /root/files
[root@hahaha /]# ll /root/files
-rw-r--r--. 1 root root 81  8月  3 20:52 /root/files
 

#52、将整个 /etc 目录下的文件全部打包并用 gzip 压缩成/back/etcback.tar.gz

[root@hahaha ~]# tar  -czvf  /back/etcback.tar.gz  /etc

  • 23
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值