第三次笔试总结
一、基础
1.阐述绝对路径和相对路径的区别
绝对路径:只要是以'/' 开始的都算是绝对路径
相对路径:是相对于当前目录来说。
2.简述软链接与硬链接的区别
软链接:(就是一个快捷方式)
1)ln -s命令创建软链接
2)支持目录创建软链接,并且支持跨越分区系统
3)软链接文件与源文件的inode不同
4)删除软链接文件,对源文件及硬链接文件无任何影响
硬链接(相当于源文件的副本)
1)ln命令用来创建硬链接
2)目录不能创建硬链接,并且不可以跨越分区系统
3)硬链接文件与源文件的inode相同
4)删除文件的硬链接文件,对源文件及链接文件无任何影响,删除源文件,对硬链接无影响,回导致软链接失效,删除源文件及其硬链接文件,整个文件会被真正的删除。
3.简述命令的执行流程
1)判断命令是否通过绝对路径执行
2)判断命令是否存在alias别名
3)判断用户输入的是内置命令还是外置命令
4)Bash内部命令直接执行,外部命令检测是否存在缓存
5)通过$PATH变量查找命令,有执行,无报错(报错:command not found)
4.写出查询file.txt以abc结尾的行
[root@wyw-10 ~]# grep "abc$" file.txt
5.查找file.log文件中的包关键字"helloworld"的内容,及其上下两行,重定向到1.txt
[root@wyw-10 ~]# grep "helloworld" file.log >1.txt
6.假设公司研发部的用户David和Peter属于组A
(1)建立相应的用户和组,并设置相应的对应关系
(2)建立目录 yf_a,该目录里面的文件只能由研发部人员读取、增加、删除、改以及执行,其他用户不能对该目录进行任何操作
(3)建立目录 yf_b,该目录里面的文件只有研发部的 David 拥有所有权限,研发部的其他人只有查看权限,其他部门不能进行任何操作
(1)[root@wyw-10 ~]# groupadd A
[root@wyw-10 ~]# useradd David -g A
[root@wyw-10 ~]# useradd Peter -g A
(2)[root@wyw-10 ~]# mkdir /yf_a
[root@wyw-10 ~]# chmod 760 /yf_a
(3)[root@wyw-10 ~]# mkdir /yf_b
[root@wyw-10 /]# chown David.A yf_b
[root@wyw-10 /]# chmod 740 yf_b
7.有一用户 oldboy,及用户组 oldboy,在 code目录下创建的所有文件自动归属于 oldboy 组所有
[root@wyw-10 ~]# groupadd oldboy
[root@wyw-10 ~]# useradd oldboy -g oldboy
[root@wyw-10 ~]# mkdir /code
[root@wyw-10 ~]# chown oldboy.oldboy code/
8.有两个用户组 python 及 Linux,python 组可以修改读取/home/python/目录下所有内容,但不能让 Linux 组读取;Linux 组可以修改读取/home/linux/目录下所有文件,但不能让 python组读取。给出配置命令。
[root@wyw-10 ~]# groupadd python
[root@wyw-10 ~]# groupadd Linux
[root@wyw-10 ~]# chown .python /hom/python
[root@wyw-10 ~]# chmod 700 /home/python
[root@wyw-10 ~]# chown .Linux /home/Linux
[root@wyw-10 ~]# chmod 700 /home/Linux
二、find相关
1.找出/tmp 目录下,属主不是 root 的文件
[root@wyw-10 ~]# find /tmp -type f ! -user root
2.查找/var 目录下属主为 old,且属组为 boy的文件
[root@wyw-10 ~]# find /var/ -type f -user old -group boy
3.查找/var 目录下 7 天以前修改、且属组为root 的文件
[root@wyw-10 ~]# find /var/ -type f -mtime +7 [-a] -group root
PS:[-a]表示可写可不写,因为默认是-a
4.查找/etc 目录下大于 1M 且类型为普通文件的所有文件
[root@wyw-10 ~]# find /etc/ -type f -size +1M
5.查找/etc/目录下大于 100k,小于 1M 的文件
[root@wyw-10 ~]# find /etc/ -type f -size +100k [-a] -size -1M
6.查找/目录下文件名包含 txt 的文件
[root@wyw-10 ~]# find / -type f -name "*.txt"
7.查找/目录下属主是 oldboy 或者属主是oldgirl 的文件
[root@wyw-10 ~]# find / -type f -user oldboy -o -user oldgir
8.删除/tmp 目录下 15 天前的文件
[root@wyw-10 ~]# find /tmp -type f -mtime +15 |xargs rm -f——第一种方式
[root@wyw-10 ~]# find /tmp -type f -mtime +15 -exec rm -f {} ;——第二种方式
[root@wyw-10 ~]# find /tmp -type f -mtime +15 -delete——第三种方式
9.查找根下名为 1.txt 或 2.txt 的文件
[root@wyw-10 ~]# find / -type f -name "1.txt" -o -name "2.txt"
- 查找/tmp 目录下所有文件并删除
[root@wyw-10 ~]# find /tmp -type f -exec rm -f {} ;
[root@wyw-10 ~]# find /tmp -type f -delete
[root@wyw-10 ~]# find /tmp -type f |xargs rm -f
find的相关说明
参数:
f 文件
d 目录
s socket套接字文件
l 链接文件
c 字符设备
b 块设备
三、tar相关
1.使用 zip 打包/etc 目录。
[root@wyw-10 ~]# zip etc.zip /etc/ -r
2.用 zip 打包/opt 目录,要求不显示打包过程。
[root@wyw-10 ~]# zip opt.zip /opt/ -qr
3.解压/data/etc.zip 到当前目录
[root@wyw-10 ~]# unzip /data/etc.zip
4.已知文件 oldboy.zip,在不解压的情况下,如何查看该文件的内容。
[root@wyw-10 ~]# unzip -l oldboy.zip
5.将/data/old.tar.gz 解压到/opt 目录下
[root@wyw-10 ~]# tar xf /data/old.tar.gz -C /opt /
6.不解压的情况下,查看/data/old.tar.gz 压缩包中都有什么内容
[root@wyw-10 ~]# tar tf /data/old.tar.gz
7.打包/etc/目录,要求不打包/etc/hosts 这个文件。
[root@wyw-10 ~]# tar czf etc.tar.gz /etc/ --exclude=/etc/hosts
8.打包/etc/目录,要求不打包/etc/hosts 和/etc/passwd 这两个文件。
[root@wyw-10 ~]# tar czf etc.tar.gz /etc/ --exclude=/etc/hosts --execlude=/etc/passwd
[root@wyw-10 ~]# tar czf etc.tar.gz /etc/ --exclude=/etc/{hosts,passwd}
9.打包/etc/目录,命令以 ip 地址方式的压缩包: 比如: 10.0.0.200_etc.tar.gz
[root@wyw-10 ~]# tar czf 2}')_etc.tar.gz /etc/
10.打包/etc/目录,要求以.bz2 格式
[root@wyw-10 ~]# tar cjf etc.tar.bz2 /etc/
压缩相关的说明
(1)zip
-r 递归压缩目录
-q 不显示打包过程
-v 显示压缩过程
-V 保持压缩文件的原有属性
-T 查看zip压缩包是否是完整的
(2)unzip
-l 不解压压缩查看压缩包中的内容
-t 查看压缩文件是否正确
-d 解压至指定目录
(3)gzip
-d 解压gzip的压缩包
zcat 不解压查看压缩包文件内容
(4)tar
czf 打包tar.gz格式
cjf 打包tar.bz格式
cJf 打包tar.xz格式
xf 自动选择解压模式
tf 查看压缩报内容
zxf 解压tar.gz格式
jxf 解压tar.bz格式
--hard-dereference 打包硬链接
--exclude 再打包的时候写入需要排除文件或目录
举例
打包/etc/目录,命令以ip地址+当前时间方式的压缩包: 比如: 10.0.0.98_2019-4-23_etc.tar.gz
[root@wyw ~]# tar czf $(ifconfig ens33|awk 'NR==3{print $2}')_$(date+%F)_etc.tar.gz $(find /etc/ -type d)
10.0.0.200_2019.08.24_etc.tar.gz
四、软件安装相关
1.使用 rpm 命令安装 tree 软件
rpm -ivh tree
2.查看你的服务器中是否安装 httpd 这个软件
[root@wyw-10 ~]# rpm -q httpd
3.查看 httpd 软件包里面的内容
[root@wyw-10 ~]# rpm -qi httpd
4.查看 httpd 软件包的详细信息
[root@wyw-10 ~]# rpm -qc httpd
- 查看一下 netstat 这个命令属于哪个软件包
[root@wyw-10 ~]# rpm -qf netstat
- 卸载 sl 这个命令
[root@wyw-10 ~]# rpm -e sl
7.已知服务的 mongodb 的版本为 3.0,现将mongodb 这个软件版本升级为 4.0,请给出 rpm升级命令
rpm -Uvh mongodb-4.0
- yum 安装 rsync 这个软件
[root@wyw-10 ~]# yum install rsync -y
- yum 安装多个软件,例如 sl、lsof、net-tools、nmap 等
[root@wyw-10 ~]# yum install -y sl lsof net-tools nmap
10.查看你的服务器中有哪些可用的 yum 源仓库。
[root@wyw-10 ~]# yum repolist
软件安装相关说明
(1)RPM
-q 查看指定软件包是否安装
-qa 查看系统中已安装的所有rpm软件包列表
-qi 查看指定软件的纤细信息
-ql 查询指定软件的详细信息
-qc 查询指定软件包的配置文件
-qf 查询文件或目录属于哪个rpm软件
-e 卸载
五、进阶
1.将“I am student”重定向到/root/bgx1.txt 中
[root@wyw-10 ~]# echo "I am student" > /root/bgx1.txt
2.简述源码编译的流程
1)下载代码安装包软件
2)tar解包,解压并释放源代码包到指定目录
3)./configure配置,生成makefile文件
4)make install安装
5)测试及应用、维护软件
3.查找/etc/目录下以.conf 结尾、修改时间为最近七天的文件,打包压缩为/tmp/conf.tar.gz
[root@wyw-10 ~]# tar czf etc.tar.gz $(find /etc/ -type f -name ".conf" -mtime -7) /etc/
[root@wyw-10 ~]# find /etc/ -type f -name ".conf" -mtime -7 |xargs tar czf etc.tar.gz
4.查找/目录下以 a 开头的目录,打包压缩为zip 结尾的压缩包
[root@wyw-10 ~]# find / -type d -name "a*" |xargs zip a.zip
5.查找/目录下,属主为 oldboy 的文件,复制到/home/oldboy/目录下
[root@wyw-10 ~]# find / -type f -user oldboy -exec cp {} /home/oldboy ;
六、翻译
- [root@test-200 ~]# cd /rot
-bash: cd: /rot: No such file or directory——没有这样的文件或目录 - [root@test-200 ~]# mdkir a
-bash: mdkir: command not found——找不到命令 - [root@test-200 ~]# mkdir a
mkdir: cannot create directory ‘a’: File exists——无法创建目录"a":文件存在 - [root@test-200 ~]# rm a
rm: cannot remove ‘a’: Is a directory——无法删除"a":是一个目录
5.[root@test-200 ~]# rm a.txt
rm: remove regular empty file ‘a.txt’?——删除常规文件"a.txt" - [root@test-200 ~]# cp /tmp/a.txt /root/a.txt
cp: overwrite ‘/root/a.txt’? 是否覆盖'/root/a.txt' - [root@test-200 ~]# id www
id: www: no such user——没有这样的用户 - [test@test-200 /]$ cd /root
bash: cd: /root: Permission denied——权限拒绝 - [root@test-200 /tmp]# cp -q a.txt c.txt
cp: invalid option -- 'q'——无效选项--"q" - [root@test-200 /home]# useradd test
useradd: user 'test' already exists——用户"test"已经存在