第四天总结与练习

第五章

总结
在这里插入图片描述

1、文件内容查看:
(1)查看/etc/passwd文件的第6行

[root@localhost ~]#head -num(指定显示文件num行的内容) /路径/文件

在这里插入图片描述

(2)查看/etc/selinux/config 以 SELINUX开头的行

[root@localhost ~]#grep ^[SELINUX] /etc/selinux/config

在这里插入图片描述

(3)查找/etc/ssh/sshd_config 以no结尾的行

[root@localhost ~]# grep no$ /etc/ssh/sshd_config

在这里插入图片描述

(4)过滤/etc/ssh/sshd_config 包含数字的行

[root@localhost ~]#grep -v [0-9] /etc/ssh/sshd_config

在这里插入图片描述

2、文本处理命令:
(1)查看/etc/passwd文件以 : 为分隔符的第一列内容,并按字母逆序排序

[root@localhost ~]#cut -d : -f 1 /etc/passwd | sort -rn

在这里插入图片描述

(2)使用cut命令将当前主机的ip地址切割显示

[root@localhost ~]# ip a | grep 24 | grep ens160 | tr -s " " | cut -d " " -f 3 | cut -d / -f 1

在这里插入图片描述

第六章

总结
在这里插入图片描述

1、复制、移动
(1)在/test目录下创建一个子目录dir,将/etc/passwd复制到该目录

[root@localhost test]# cp /etc/passwd dir

在这里插入图片描述

(2)将/etc/ssh/sshd_config文件复制到/test目录

[root@localhost test]# cp /etc/ssh/sshd_config /root/test

在这里插入图片描述

(3)将/etc/yum.repos.d/目录复制到/test目录

[root@localhost test]# cp -r /etc/yum.repos.d /root/test

在这里插入图片描述

(4)将/etc/hosts文件复制到/test目录

[root@localhost test]# cp /etc/hosts /root/test

在这里插入图片描述

(5)将/etc/hostname文件复制到/test目录

[root@localhost test]# cp /etc/hostname /root/test

在这里插入图片描述

(6)将/test/sshd_config文件移动到/test/dir目录下并改名为sshd.conf

[root@localhost test]# mv sshd_config dir/
[root@localhost dir]# mv sshd_config sshd.conf

在这里插入图片描述

2、文件查找
(1)在$HOME目录及其子目录中,查找2天前被更改过的文件

[root@localhost /]# find $HOME -ctime +1 

在这里插入图片描述

(2)在/etc/目录下寻找以host开头的文件

[root@localhost etc]# find /etc -name "host*" -print

在这里插入图片描述

(3)在/test/下面查找目录文件

[root@localhost /]# find /root/test -type d -print

在这里插入图片描述

(4)在/test目录及子目录中,查找超过2KB的文件

[root@localhost /]# find /root/test -size +2M

3、打包压缩
(1)将/test目录下的所有文件和文件夹全部压缩成myfile.zip文件

[root@localhost ~]# zip -r myfile.zip test/

在这里插入图片描述

(2)把myfile.zip文件解压到 /opt

[root@localhost ~]# unzip myfile.zip -d /opt

在这里插入图片描述

(3)将/opt目录下的文件全部打包并用gzip压缩成/test/newfile.tar.gz

[root@localhost /]# tar czf /test/newfile.tar.gz opt/

(5)查看/test/newfile.tar.gz文件中有哪些文件?

[root@localhost /]# ls /test/newfile.tar.gz opt/

在这里插入图片描述

(6)将newfile.tar.gz下载至windows客户端主机

sftp> get /root/test/newfile.tar.gz D:/test/

在这里插入图片描述

(7)在/test目录内,备份/etc下的所有文件并保留其权限

[root@localhost test]# tar -cpf newfile_1.tar /etc

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值