二、awk
2.1 显示1.txt文件第3到第10行的内容?(2分)
[root@localhost ~]# sed -n '3,10p' 1.txt
2.2 取出IP地址(2分)
2.3 写一个文件,文件内容如下
cat >>test.txt<<EOF
server {
lisTEN 80;
server_nAme docs.xuliangwei.com;
root /code/dOcs
index INDEX.html;
}
EOF
2.3.1过滤docs.xuliangwei.com这段关键字(2分)
[root@localhost ~]# grep docs.xuliangwei.com test.txt
2.3.2同时过滤出root和index的行,不区分大小写(2分)
[root@localhost ~]# egrep -i "docs.xuliangwei.com|index|root" test.txt
2.3.3过滤index,区分大小写(2分)
[root@localhost ~]# grep "index" test.txt
2.3.4过滤出带"O"的行,不区分大小写(2分)
[root@localhost ~]# grep -i "O" test.txt
2.3.5过滤出不带";"的行(2分)
[root@localhost ~]# grep -v ";" test.txt
3.4 将"web3_access.log"上传至你的linux服务器
[root@localhost ~]# rz
2.4.1统计出该文件IP地址(第一列)出现的次数,并按正序对其进行排序(2分)
[root@localhost ~]# awk '{print $1}' web3_access.log | uniq -c | sort -n
2.4.2统计该文件内HTTP状态返回码出现的次数(例如200,404,403,在第九列),并按照倒序进行排序(2分)
[root@localhost ~]# awk '{print $9}' web3_access.log | sort | uniq -c | sort -nr
2.4.3过滤出所有状态返回码是200的行,并将这些返回码为200行的全部替换成300(2分)
[root@localhost ~]# grep "200" web3_access.log |xargs sed -i 's/200/300/g' web3_access.log
3.5 使用hostnamectl查看当前系统信息
[root@localhost ~]# hostnamectl
Static hostname: localhost.localdomain
Icon name: computer-vm
Chassis: vm
Machine ID: 143ddbe896784d29821a81c98b6933e3
Boot ID: 255f172d24d74b11835b9dabc43ea307
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-693.el7.x86_64
Architecture: x86-64
2.5.1取出kernel内核版本信息(2分)
[root@localhost ~]# hostnamectl | grep Kernel | awk '{print $3}'
2.5.2取出系统名称(2分)
[root@localhost ~]# hostnamectl | grep System | awk -v OFS="\t" '{print $3,$4,$5}'
2.5.3取出系统版本信息,只显示"linux 7"(2分)
[root@localhost ~]# hostnamectl | grep System | awk -v OFS="\t" '{print $4,$5}'
三、用户与权限
3.1 在Linux系统中,哪个文件保存着用户信息(2分)
A:/etc/Profile B:/etc/passwd
C:/usr/bin/env D:/boot
3.2 一个用户想要修改dir目录下的file文件,他需要对dir目录以及file文件有什么权限(2分)
A:file的写权限和dir目录(以及一直向上到/目录)的执行权限
B:只需要file的写权限 C:只需file的读和写权限
D:file的写权限和dir目录(以及一直向上到/目录)的写权限
3.3 默认情况下管理员创建了一个用户,就会在()目录下创建一个用户主目录(2分)
A:/usr B:/home C:/root D:/etc
3.4为脚本程序指定执行权限的命令参数是(2分)
A:chmod +x filename.sh B:chown +x filename.sh
C:chmod +w filename.sh D:chown +r filename.sh
3.5 如果执行命令 # chmod 746 file.txt , 那么该文件的权限是?(2分)
A:rwxr--rw- B:rw-r--r--
C:–xr—rwx D:jrwxr—r—
3.6 某文件的权限为:drw--r--r--,用数值形式表示该权限,则该八进制数为(644),该文件属性是(目录)(2分)
3.7 某个服务器有a.sh脚本,用户权限为644,需要执行什么命令,才可以执行./a.sh命令(2分)
[root@localhost ~]# chmod +x a.sh
3.8 唯一标识每一个用户的是用户的_uid_和_gid_(2分)
3.9 将以下权限翻译成数字,将数字权限用字母表示(14分)
r 4 w 2 x 1
rw- r-x r-- 6 5 4
rw- r-- r-- 6 4 4
rwx --x --x 7 1 1
rw- --- --- 6 0 0
rwx r-- r-- 7 4 4
rw- rw- r-- 6 6 4
751 rwxr_x__x
771 rwxrwx__x
632 rw__wx_w_
3.10 设置/home/user1/test文件权限为所有者可读可写可执行,所有组可读可写,其他所有账户可读,并将该文件的所有者和所有组都修改为root(3分)
chmod 764 /home/user1/test
chown root:root /home/user1/test
3.11 当用户zabbix对/testdir 目录有写和执行权限时,该目录下的只读文件file1 是否可修改和删除?(3分)
3.12 把jacky的密码设置为123(3分)
echo "123" | passwd --stdin jacky
3.13 使用"ls -l /"以长格式查看根目录,写出引号内容所代表的详细含义(4分)
目录 权限 属主属组
“dr-xr-xr-x.” 5 “root root” 4096 May 16 01:36 boot
3.14 当用户mysql对/data/DB目录无读权限,但是拥有写和执行权限,意味着能做哪些操作,无法做哪些操作?(3分)
执行该目录下的可执行文件
可在命令行修改该目录下的文件
四、进阶
4.1 如果某一天你误操作了"rm -rf *",会发生哪些情况(3分)
系统被删除了
4.2 用命令行更改config.txt文件,把里面所有的"name"更改为"address" (3分)
sed -i 's/name/address/g' config.txt
4.3 用awk获取文件中第三行的倒数第二列字段(2分)
sed -n '3p' 1.txt | awk '{print $(NF-1)}'
4.4 删除file.txt文件中的空行(3分)
sed -i '/^$/d' 1.txt
4.5 删除/tmp目录下所有a开头的文件(3分)
rm -rf /tmp/a*
五、翻译(每个2分)
5.1 [root@test-200 ~]# cd /rot
-bash: cd: /rot: No such file or directory
没有/rot 这个目录
5.2 [root@test-200 ~]# mdkir a
-bash: mdkir: command not found
没有mkdir这个命令
5.3 [root@test-200 ~]# mkdir a
mkdir: cannot create directory ‘a’: File exists
a这个目录已存在
5.4 [root@test-200 ~]# rm a
rm: cannot remove ‘a’: Is a directory
不能使用rm删除a这个目录,得加rf
5.5 [root@test-200 ~]# rm a.txt
rm: remove regular empty file ‘a.txt’?
确定删除一个空文件a.txt
5.6 [root@test-200 ~]# cp /tmp/a.txt /root/a.txt
cp: overwrite ‘/root/a.txt’?
确定要覆盖这个文件?
5.7 [root@test-200 ~]# id www
id: www: no such user
没有www这个用户
5.8 [test@test-200 /]$ cd /root
bash: cd: /root: Permission denied
切换到/root这个目录被拒,无权限
5.9 [root@test-200 /tmp]# cp -q a.txt c.txt
cp: invalid option -- 'q'
-q 是一个无效的参数
5.10 [root@test-200 /home]# useradd test
useradd: user 'test' already exists
test 这个用户已经存在了,不能重复添加