Linux day9作业习题

1.已知sort.log文件内容如下,请根据文件内容的第二列进行倒序排序。
cat >>sort.log<<'EOF'
218.65.30.25 68652
218.65.30.53 34326
218.87.109.154 21201
112.85.42.103 18065
112.85.42.99 17164
218.87.109.151 17163
218.87.109.150 17163
218.65.30.61 17163
218.65.30.126 17163
218.65.30.124 17163
EOF

[root@linux10 ~]# sort -nk 2r sort.log
218.65.30.25 68652
218.65.30.53 34326
218.87.109.154 21201
112.85.42.103 18065
112.85.42.99 17164
218.65.30.124 17163
218.65.30.126 17163
218.65.30.61 17163
218.87.109.150 17163
218.87.109.151 17163

2.统计系统文件/etc/services有多少行。

wc -l /etc/services

[root@linux10 ~]# wc -l /etc/passwd
19 /etc/passwd

3.已知文件内容如下,请对该文件的字符串出现的次数进行统计,并从小到大的进行排序出来。
cat>>uniq.txt<<'EOF'
oldboy
oldgirl
oldboy
egon
student
oldgirl
oldboy
EOF

[root@linux10 ~]# sort uniq.txt | uniq -c | sort -n
1 egon
1 student
2 oldgirl
3 oldboy

4.取出系统中的文件/etc/passwd的第七列(以:为分隔符)。

[root@linux10 ~]# cut -d ':' -f 7 /etc/passwd
/bin/bash
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/bin/sync
/sbin/shutdown
/sbin/halt
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin

5.已知文件test.txt内容如下,请给出输出test.txt文件内容时,不包含oldboy字符串的命令。
test
qiudao
oldboy

[root@linux10 ~]# grep -v 'oldboy' test.txt
test
quidao

6.只查看/etc/passwd文件内第5到第15行的内容

[root@linux10 ~]# head -15 /etc/passwd | tail -11
lp❌4:7:lp:/var/spool/lpd:/sbin/nologin
sync❌5:0:sync:/sbin:/bin/sync
shutdown❌6:0:shutdown:/sbin:/sbin/shutdown
halt❌7:0:halt:/sbin:/sbin/halt
mail❌8:12:mail:/var/spool/mail:/sbin/nologin
operator❌11:0:operator:/root:/sbin/nologin
games❌12💯games:/usr/games:/sbin/nologin
ftp❌14:50:FTP User:/var/ftp:/sbin/nologin
nobody❌99:99:Nobody:/:/sbin/nologin
systemd-network❌192:192:systemd Network Management:/:/sbin/nologin
dbus❌81:81:System message bus:/:/sbin/nologin

7.把test.txt文件中的oldboy替换为oldgirl,给出命令

8.test.txt 的内容如下,要求过滤出不包含zengdao的行。
oldboy
oldgirl
zengdao

grep -v 'zengdao' test.txt

9.把文件/etc/passwd文件中的/sbin/nologin替换为/bin/bash

10.把/etc/selinux/config文件中的SELINUX=enforcing行中的enforcing替换成disabled

vim /etc/selinux/config

11.现将文件b.txt 中的所有123 替换成def,请问如何实现?

tr '123' 'def' < b.txt

12.将文件的test.txt中的第10行的oldboy改为oldgirl

13.请执行命令取出linux中eth0的IP地址分别是ip和ifconfig的命令(请用cut,有能力者也可分别用awk,sed命令答)。

15.删除/etc/passwd文件的前三行内容。

16.统计文件/etc/hosts的行数?你能使用几种方法实现?

wc -l /etc/hosts grep -c '.*' /etc/hosts

17.统计文件/etc/services的字节数。你能使用几种方法实现?

wc -c /etc/services

18.执行下面的命令echo "Im qiuzengjia , is QQ 1176494252" >file.txt,要求取出该文件中的姓名和QQ号。
19.执行如下命令
cat > file.txt <<EOF
abc
123
abc
123
def
EOF
要求去除重复的列

[root@linux10 ~]# sort file.txt | uniq

20.接上题,取出每列出现的次数

[root@linux10 ~]# sort file.txt | uniq -c

21.统计/var/log下的文件个数,不统计下级目录。

22.统计/var/log下的所有文件和目录个数,不包含隐藏文件。

[root@linux10 ~]# locate /var/log/ | wc -l
41

23.以“:”为分隔符,取出/etc/passwd第一行的最后一列的内容

[root@linux10 ~]# cut -d ':' -f7 /etc/passwd | head -1
/bin/bash

24.过滤出/etc/passwd以nologin结尾的内容,并统计行数

[root@linux10 ~]# grep -c '.*nologin' /etc/passwd
15

25.分析如下日志内容,每个域名被访问次数

cat>catweb.log <<EOF
http://www.oldboy.com/index.html
http://www.oldboy.com/1.html
http://post.oldboy.com/index.html
http://mp3.oldboy.com/index.html
http://www.oldboy.com/3.html
http://post.oldboy.com/2.html
EOF

[root@linux10 ~]# sort catweb.log | uniq -c
1 http://mp3.oldboy.com/index.html
1 http://post.oldboy.com/2.html
1 http://post.oldboy.com/index.html
1 http://www.oldboy.com/1.html
1 http://www.oldboy.com/3.html
1 http://www.oldboy.com/index.html

posted @ 2020-06-18 21:27  nick_xm  阅读(220)  评论(0编辑  收藏  举报