CHCSA第二次作业

news2024/9/25 5:23:36

#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 

方法二:

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

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

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

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

:r /boot/grub2/grub.cfg

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

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

g/#/d

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

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

set nu

#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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1975951.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Pandas的30个高频函数使用介绍

Pandas是Python中用于数据分析的一个强大的库,它提供了许多功能丰富的函数。本文介绍其中高频使用的30个函数。 read_csv(): 从CSV文件中读取数据并创建DataFrame对象。 import pandas as pd df pd.read_csv(data.csv) read_excel(): 从Excel文件中读取数据…

嗖嗖移动业务大厅(JDBC)

一、项目介绍 1、项目背景: 该项目旨在模拟真实的移动业务大厅,。用户可以注册新卡、查询账单、管理套餐、充值话费、打印消费记录等功能。同时,项目还模拟了用户使用场景,如通话、上网、发短信等,并根据套餐规则进行相应的扣费…

AutoCAD ObjectArx二次开发(二) 关于程序入口的介绍

在上一章节中,我们介绍了环境搭建和程序插件的加载,基本的编程模板(框架)已经准备就绪。接下来,我们将开始编写自己的业务逻辑。ARX开发的核心在于将自定义函数注册到库中,并通过指定的调用命令来实现功能。…

【论文解读|Data Intelligence】 Large Knowledge Model: Perspectives and Challenges

论文链接:Large Knowledge Model: Perspectives and Challenges (sciengine.com) 来源: Data Intelligence 论文介绍: 文章简述了人类语言和世界知识的紧密关系,对比了语言模型和知识图谱在表示和处理人类知识方面的优缺点&…

Candance Allegro 入门教程笔记:PCB封装库的组成元素

文章目录 一、PCB封装库的组成元素二、使用Padstack Edictor制作封装焊盘引脚三、PCB Editor软件创建贴片封装(STM32F103T8U6 QFN36 为例)1.引入库2.读入数据 一、PCB封装库的组成元素 一般来说,针对于Allegro软件,完整的封装是由…

blender里的辉光

cycle的辉光, 点开支持后期效果 eevee的辉光,直接点bloom就行。 eevee的透明

GORM更新操作(Save、Update、Updates)

在 Go 语言的 Web 开发中,GORM 是一个广泛使用的 ORM (Object-Relational Mapping) 框架。它提供了一种流畅的方式来处理数据库的交互,其中包括记录的更新操作。GORM中的更新操作主要是update、updates、save这几种 操作前的准备工作:声明模…

C语言进阶版第五课—函数递归

文章目录 1. 什么是函数递归2. 函数递归的思想3. 函数递归的限制4. 函数递归练习4.1 n的阶乘4.2 按照顺序打印一个整数的每一位4.3 自定义函数不允许创建变量,求字符串长度 1. 什么是函数递归 函数递归就是函数自己调用自己 图片中的函数test(&#xff0…

Monaco 使用 TypeDefinitionProvider

Monaco 中的 TypeDefinitionProvider 和 ImplementationProvider、DefinitionProvider 类似,右键点击变量名称,现在 “选择转到类型定义”, 跳到指定位置。 通过 registerTypeDefinitionProvider 添加 TypeDefinitionProvider 处理方法 实现…

力扣SQL50 按日期分组销售产品 group_concact

Problem: 1484. 按日期分组销售产品 👨‍🏫 参考题解 select sell_date, count(distinct product) num_sold,group_concat(distinct product order by productseparator ,) products from activities group by sell_date

度量与增长——OrionX AI算力管理工具的企业价值解读

从科学计算到人工智能,从AI模型开发到AI模型训练,从双精度到半精度,从OPENGL到CUDA,GPU都扮演着关键角色。本文主要从运维的人员的角度出发,来探讨GPU使用过程中遇到的管理问题和创新性解决办法。 GPU的管理和监控 相…

《电容-排容》

节省电路板空间:将多个电容集成在一个封装里,减小了占用的电路板面积。 便于安装和布线:提高生产效率和电路布局的便利性。 一致性较好:由于是同一批次生产,各电容的性能参数较为一致。 【参数】品牌,封…

网络云相册实现--nodejs后端+vue3前端

目录 主页面 功能简介 系统简介 api 数据库表结构 代码目录 运行命令 主要代码 server apis.js encry.js mysql.js upload.js client3 index.js 完整代码 主页面 功能简介 多用户系统,用户可以在系统中注册、登录及管理自己的账号、相册及照片。 每…

Maven实战(四)- 生命周期和插件

Maven实战(四)- 生命周期和插件 文章目录 Maven实战(四)- 生命周期和插件1.何为生命周期2.生命周期2.1.Clean生命周期2.1.Default生命周期2.3.Site生命周期 3.Maven插件3.1.插件目标3.2.插件绑定3.2.1.内置插件3.2.2.自定义插件 4…

算法学习day28

一、寻找右区间(二分法) 题意:题目很容易理解 但是转换为二分法有点晦涩 给你一个区间数组 intervals ,其中 intervals[i] [starti, endi] ,且每个 starti 都 不同 。区间 i 的 右侧区间 可以记作区间 j ,并满足 startj > e…

gptpdf深度解析:开源文档处理技术全攻略

目录 一、引言二、gptpdf 是什么?三、gptpdf 的功能特性1. 精准的 PDF 元素解析能力2. 对复杂文档结构的处理示例3. 高效的处理速度4. 低成本的优势 四、gptpdf 应用场景1. 学术研究与文献处理2. 企业文档管理3. 软件开发中的文档转换 五、gptpdf 代码示例1. 基本的…

【Vue3】组件通信之v-model

【Vue3】组件通信之v-model 背景简介开发环境开发步骤及源码总结 背景 随着年龄的增长,很多曾经烂熟于心的技术原理已被岁月摩擦得愈发模糊起来,技术出身的人总是很难放下一些执念,遂将这些知识整理成文,以纪念曾经努力学习奋斗的…

图像梯度与几种算子

“滤波器”也可以称为“卷积核”,“掩膜”,“算子”等。 1、Sobel算子 Sobel算子是一个33的卷积核,利用局部差分寻找边缘,计算得到梯度的近似值。x和y方向的Sobel算子分别为: 梯度有方向,对于一个图像&a…

电子元器件—三极管(一篇文章搞懂电路中的三极管)(笔记)(面试考试必备知识点)

三极管的定义及工作原理 1. 定义 三极管(Transistor)是一种具有三层半导体材料(P-N-P 或 N-P-N)构成的半导体器件,用于信号放大、开关控制和信号调制等应用。三极管有三个引脚:发射极(Emitter…

SpringBoot智慧旅游在线平台的设计与实现(源码+论文+部署讲解等)

博主介绍:✌全网粉丝10W,csdn特邀作者、博客专家、CSDN新星计划导师、Java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和学生毕业项目实战,高校老师/讲师/同行前辈交流✌ 技术范围:SpringBoot、Vue、SSM、HLM…