3.25小练习题
Posted 0_o
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了3.25小练习题相关的知识,希望对你有一定的参考价值。
1.过滤出/etc/passwd以nologin结尾的内容,并统计行数
[root@localhost ~]# grep -n nologin$ /etc/passwd
2:bin:x:1:1:bin:/bin:/sbin/nologin
3:daemon:x:2:2:daemon:/sbin:/sbin/nologin
4:adm:x:3:4:adm:/var/adm:/sbin/nologin
5:lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
9:mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10:operator:x:11:0:operator:/root:/sbin/nologin
11:games:x:12:100:games:/usr/games:/sbin/nologin
12:ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
13:nobody:x:99:99:Nobody:/:/sbin/nologin
14:systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
15:dbus:x:81:81:System message bus:/:/sbin/nologin
16:polkitd:x:999:998:User for polkitd:/:/sbin/nologin
17:sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
18:postfix:x:89:89::/var/spool/postfix:/sbin/nologin
2.使用ifconfig命令获取当前的IP地址
[root@localhost <sub>]# ifconfig
-bash: ifconfig: command not found
[root@localhost </sub>]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:91:55:90 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.105/24 brd 10.0.0.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::f205:db2c:61:24ae/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3.将/etc/sysconfig/selinux文件中的SELINUX=enforcing替换为SELINUX=disabled
[root@localhost <sub>]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
[root@localhost </sub>]# cat /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
4.分析如下日志内容,每个域名被访问次数
cat web.log
https://blog.driverzeng.com/index.html
https://blog.driverzeng.com/1.html
http://post.driverzeng.com/index.html
http://mp3.driverzeng.com/index.html
https://blog.driverzeng.com/3.html
http://post.driverzeng.com/2.html
[root@localhost ~]# sort -n web.log |cut -d : -f 2 |cut -d / -f 3 |uniq -c
1 mp3.driverzeng.com
2 post.driverzeng.com
3 blog.driverzeng.com
5.用普通用户身份登陆虚拟机上完成练习
[root@localhost <sub>]# adduser zxw
[root@localhost </sub>]# su zxw
[zxw@localhost root]$ cd
[zxw@localhost ~]$
6.在用户家目录下创建6个文件 song1.mp3 ~ song6.mp3
[zxw@localhost <sub>]$ touch song1..6.mp3
[zxw@localhost </sub>]$ ll
total 0
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song1.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song2.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song3.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song4.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song5.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song6.mp3
7.把上题创建的songX.mp3文件移动到Music目录下(不存在则创建)
[zxw@localhost <sub>]$ mkdir Music
[zxw@localhost </sub>]$ ll
total 0
drwxrwxr-x. 2 zxw zxw 6 Mar 27 16:57 Music
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song1.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song2.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song3.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song4.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song5.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song6.mp3
[zxw@localhost <sub>]$ mv song1..6.mp3 Music
[zxw@localhost </sub>]$ ll Music
total 0
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song1.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song2.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song3.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song4.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song5.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song6.mp
8.在用户家目录下创建三个目录,分别为 friends,family,work
[zxw@localhost ~]$ mkdir friends family work
9.切换到friends目录下,把Music目录下的song1.mp3 ~ song3.mp3 拷贝到当前目录
[zxw@localhost ~]$ cd friends
[zxw@localhost friends]$ ll
total 0
[zxw@localhost friends]$ cp /home/zxw/Music/song1..3.mp3 /home/zxw/friends/
[zxw@localhost friends]$ ll
total 0
-rw-rw-r--. 1 zxw zxw 0 Mar 27 17:06 song1.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 17:06 song2.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 17:06 song3.mp3
10.切换到family目录下,把Music目录下的song4.mp3 ~ song6.mp3 移动到当前目录
[zxw@localhost friends]$ cd
[zxw@localhost ~]$ cd family
[zxw@localhost family]$ ll
total 0
[zxw@localhost family]$ mv /home/zxw/Music/song4..6.mp3 /home/zxw/family/
[zxw@localhost family]$ ll
total 0
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song4.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song5.mp3
-rw-rw-r--. 1 zxw zxw 0 Mar 27 16:55 song6.mp3
11.切换到用户主目录
[zxw@localhost family]$ cd
[zxw@localhost ~]$
12.删除family目录
[zxw@localhost <sub>]$ ll
total 0
drwxrwxr-x. 2 zxw zxw 57 Mar 27 17:12 family
drwxrwxr-x. 2 zxw zxw 57 Mar 27 17:06 friends
drwxrwxr-x. 2 zxw zxw 57 Mar 27 17:12 Music
drwxrwxr-x. 2 zxw zxw 6 Mar 27 17:00 work
[zxw@localhost </sub>]$ rm -fr family
[zxw@localhost ~]$ ll
total 0
drwxrwxr-x. 2 zxw zxw 57 Mar 27 17:06 friends
drwxrwxr-x. 2 zxw zxw 57 Mar 27 17:12 Music
drwxrwxr-x. 2 zxw zxw 6 Mar 27 17:00 work
13.切换到friends目录,把目录下的所有文件删除
[zxw@localhost ~]$ cd friends
[zxw@localhost friends]$ rm -fr ./*
[zxw@localhost friends]$ ll
total 0
14.切换到主目录,把friends目录删除.
[zxw@localhost friends]$ cd
[zxw@localhost <sub>]$ ll
total Python怎么先排序再去头尾再累加?