第三次考试题

一、基础(每题 2 分)

1.1 阐述绝对路径与相对路径的区别

绝对路径:一切从根目录开始。
相对路径:从当前所在目录开始。

1.2 简述软连接与硬连接的区别

软连接:相当于快捷方式,删除原文件则失效,针对文件和目录,inode相同,ln -s创建
硬链接:相当于副本,删除源文件没有影响,只能针对文件,inode不相同,ln 创建

1.3 简述命令执行的流程

是否为绝对路径-->alias有无别名--->内置还是外置命令,内置执行外置查看hash缓存
-->$PATH变量查找命令,有则执行,没有则报错command not found

1.4 写出查询 file.txt 以 abc 结尾的行

grep "abc$" file.txt
awk  "/abc$/" file.txt

1.5 查找 file.log 文件中的包含关键字 “helloworld”的内容,及其上下两行的重定向到 1.txt

grep -C2 "helloworld" file.log > 1.txt

1.6 假设公司研发部的用户 David 和 Peter 属于组 A
1.6.1 建立相应的用户和组,并设置相应的对应关系

groupadd A
useradd David -G A
useradd Peter -G A

1.6.2 建立目录 yf_a,该目录里面的文件只能由研发部人员读取、增加、删除、修改以及执 行,其他用户不能对该目录进行任何操作

mkdir yf_a
chmod 770 yf_a

1.6.3 建立目录 yf_b,该目录里面的文件只有研发部的 David 拥有所有权限,研发部的其他 人只有查看权限,其他部门不能进行任何操作

chown David yf_a  或
chmod 740 yf_a

1.7 有一用户 oldboy,及用户组 oldboy,在code 目录下创建的所有文件自动归属于 oldboy 组所有

chown oldboy.oldboy code
chmod g+s code   或  chmod 2755 code

1.8 有两个用户组 python 及 Linux,python组可以修改读取/home/python/目录下所有内容,但 不能让 Linux 组读取;Linux 组可以修改读取 /home/linux/目录下所有文件,但不能让 python 组读取。给出配置命令。

groupadd python
groupadd Linux
mkdir -p /hom/python
mkdir -p /hom/linux
chown .python /hom/python
chown .Linux /hom/linux
chmod 2763 /hom/python
chmod 2763 /hom/linux

二、find 相关(每题 3 分)

2.1 找出/tmp目录下,属主不是 root 的文件

[root@madeyuan ~]# find /tmp -type f  ! -user "root" -ls

2.2 查找/var目录下属主为 old,且属组为 boy的文件

[root@madeyuan ~]# find /var -type f -user "old" -group "boy"

2.3 查找/var目录下 7 天以前修改、且属组为root 的文件

[root@madeyuan ~]# find /var -type f -mtime +7 -group "root"

2.4 查找/etc目录下大于 1M 且类型为普通文件的所有文件

[root@madeyuan ~]# find /etc -type f -size +1M

2.5 查找/etc/目录下大于 100k,小于 1M 的文 件

[root@madeyuan ~]# find / -type f -size +100k -size -1M

2.6 查找/目录下文件名包含 txt 的文件

[root@madeyuan ~]# find / -type f -name "*txt*"

2.7 查找/目录下属主是 oldboy 或者属主是 oldgirl 的文件

[root@madeyuan ~]# find / -type f -user "oldboy" -o -user "oldgirl"

2.8 删除/tmp目录下 15 天前的文件

[root@madeyuan ~]# find /tmp -type f -mtime +15 -exec rm -f {} \;

2.9 查找根下名为 1.txt 或 2.txt 的文件

[root@madeyuan ~]# find / -name "1.txt" -o -name "2.txt"

2.10 查找/tmp 目录下所有文件并删除

[root@madeyuan ~]# find /tmp -type f -exec rm -f {} \;    或
[root@madeyuan ~]# find /tmp -type f |xargs rm -f   

三、tar 相关(每题 3 分)

3.1 使用 zip 打包/etc 目录。

zip -r etc.zip /etc

3.2 用 zip 打包/opt 目录,要求不显示打包过程。

zip -rq opt.zip /opt  或 zip -r opt.zip /opt >1.txt

3.3 解压/data/etc.zip到当前目录

unzip /data/etc.zip

3.4 已知文件 oldboy.zip,在不解压的情况下,如何查看该文件的内容

unzip -l oldboy.zip

3.5 将/data/old.tar.gz 解压到/opt 目录下

tar xf /data/old.tar.gz -C /tmp/

3.6 不解压的情况下,查看/data/old.tar.gz 包中都有什么内容

tar tf /data/old.tar.gz

3.7 打包/etc/目录,要求不打包/etc/hosts这个文件。

tar czf etc.tar.gz /etc/ --exclude=etc/hosts

3.8 打包/etc/目录,要求不打包/etc/hosts和/etc/passwd这两个文件。

tar czf etc.tar.gz /etc/ --exclude=etc/hosts --exclude=etc/passwd

3.9 打包/etc/目录,命令以ip 地址方式的压缩包:比如:10.0.0.200_etc.tar.gz

tar czvf $(ifconfig |awk 'NR==2 {print $2}')_etc.tar.gz /etc/

3.10 打包/etc/目录,要求以.bz2格式

tar cjf etc.tar.bz2 /etc/

四、软件安装相关(每题3 分)

4.1 使用rpm 命令安装 tree 软件。

rpm -ivh tree-1.6.0

4.2 查看你的服务器中是否安装httpd 这个软件。

rpm -q httpd

4.3 查看httpd 软件包里面的内容。

rpm -ql httpd

4.4 查看httpd 软件包的详细信息。

rpm -qi httpd

4.5 查看一下netstat 这个命令属于哪个软件包

rpm -qf $(which netstat)  或
yum provides nettast

4.6 卸载sl 这个命令

yum remove sl -y

4.7 已知服务的mongodb 的版本为 3.0,现将mongodb这个软件版本升级为4.0,请给出 rpm升级命令

rpm -Uvh mongodb

4.8 yum 安装 rsync 这个软件。

yum install rsync

4.9 yum 安装多个软件,例如 sl、lsof、net-tools、nmap 等

yum install sl lsof net-tools nmap -y

4.10 查看你的服务器中有哪些可用的 yum 源仓库。

yum repolist

五、进阶(每题4 分)

5.1 将“I am student”重定向到/root/bgx1.txt中

echo "I am student" > /root/bgx1.txt

5.2 简述源码编译的流程

下载包——解压——生成makefile文件——make install安装

5.3 查找/etc/目录下以.conf结尾、修改时间为最近七天的文件,打包压缩为/tmp/conf.tar.gz

fin /etc -type f -name "*.conf" -mtime -7 |xrags tar czf /tmp/conf.tar.gz

5.4 查找/目录下以a 开头的目录,打包压缩为zip结尾的压缩包

find / -type d -name "a*" -exec zip -r a.zip {} \;  或
find / -type d -name "a*" |xargs zip -r a.zip 

5.5 查找/目录下,属主为oldboy 的文件,复制到/home/oldboy/目录下

find / -type f -user "oldboy" -exec cp {} /home/oldboy \;
find / -type f -user "oldboy" |xargs cp /home/oldboy/

六、翻译(每题2 分)

6.1 [root@test-200 ~]# cd /rot
-bash: cd: /rot: No such file or directory   没有这样的文件或目录
6.2 [root@test-200 ~]# mdkir a
-bash: mdkir: command not found   未找到命令
6.3 [root@test-200 ~]# mkdir a
mkdir: cannot create directory ‘a’: File exists   无法创建目录“a”:文件存在
6.4 [root@test-200 ~]# rm a
rm: cannot remove ‘a’: Is a directory   无法删除“a”:是一个目录
6.5 [root@test-200 ~]#rm a.txt
rm:remove regular empty file ‘a.txt’?   删除常规的空文件“a.txt”?
6.6 [root@test-200 ~]# cp /tmp/a.txt /root/a.txt 
cp:overwrite ‘/root/a.txt’?   覆盖 ‘/root/a.txt’?
6.7 [root@test-200 ~]# id www 
id: www: no such user    没有这样的用户
6.8[test@test-200 /]$ cd /root
bash: cd:/root: Permission denied    权限被拒绝
6.9 [root@test-200 /tmp]# cp -q a.txt c.txt 
cp: invalidoption -- 'q'     无效
6.10 [root@test-200 /home]# useradd test 
useradd: user'test' already exists   用户添加:用户“测试”已存在

你可能感兴趣的:(第三次考试题)