第五周作业
1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;
[root@zz ~]# egrep "^[[:space:]]+" /boot/grub/grub.conf
2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;
[root@zz ~]# egrep "^#[[:space:]]+[^[:space:]]" /etc/rc.d/rc.sysinit # /etc/rc.d/rc.sysinit - run once at boot time # Taken in part from Miquel van Smoorenburg's bcheckrc. # Check SELinux status # Print a text banner. # Only read this once. # Initialize hardware # Set default affinity # Load other user-defined modules
3、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;
[root@zz ~]# netstat -tan | egrep "LISTEN[[:space:]]*$" tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:59437 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:*
4、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;
[root@zz ~]# useradd bash [root@zz ~]# useradd testbash [root@zz ~]# useradd basher [root@zz ~]# useradd -s /sbin/nologin nologin [root@zz ~]# egrep "^([[:alnum:]]+).*\1$" /etc/passwd sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt nobody:x:99:99:Nobody:/:/sbin/nologin nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin ntp:x:38:38::/etc/ntp:/sbin/nologin bash:x:500:500::/home/bash:/bin/bash basher:x:502:502::/home/basher:/bin/bash nologin:x:503:503::/home/nologin:/sbin/nologin
5、显示当前系统上root、fedora或user1用户的默认shell;
egrep "^root|^fedora|^user1" /etc/passwd | cut -d: -f1,7 root:/bin/bash fedora:/sbin/tcsh user1:/sbin/nologin
6、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();
[root@zz ~]# egrep -o "[[:alpha:]]+\(\)*" /etc/rc.d/init.d/functions str() checkpid() readlink() fgrep() checkpids() kill() loop() fstab() mtab() loop() mounts() run() pidof() daemon() killproc() if( if( printf( pidfileofproc() pidofproc() status() success() failure() passed() warning() stage() success() failure() passed() warning() action() silent() strstr() confirm() dev() sub( printf( file() true() false() sysctl() random() point() crypto() [root@zz ~]#
7、使用echo命令输出一个绝对路径,使用grep取出其基名;扩展:取出其路径名
[root@zz network-scripts]# echo "/etc/sysconfig/network-scripts/ifcfg-eth1" | egrep -o "[^/]+/?$" | cut -d"/" -f1 ifcfg-eth1 [root@zz network-scripts]# echo "/etc/sysconfig/network-scripts/ifcfg-eth1" | grep -o ".*/" /etc/sysconfig/network-scripts/
8、找出ifconfig命令结果中的1-255之间数字;
ifconfig | egrep -o "\<[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]\>" 0 0 29 4 24 10 201 106 128 10 201 106 255 255 255 255 0 80 20 29 24 64 150 1 63 28 0 0 0 0 46 55 0 0 0 0 0 100 58 97 57 57 9 67 157 65 8 127 0 0 1 255 0 0 0 1 128 65 53 1 4 0 0 0 0 4 0 0 0 0 0 0 33 33 0 33 33 0
9、挑战题:写一个模式,能匹配合理的IP地址;
[root@zz tmp]# ifconfig | egrep -o "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" 10.201.106.128 10.201.106.255 255.255.255.0 127.0.0.1 255.0.0.0
10、挑战题:写一个模式,能匹配出所有的邮件地址;
[root@zz tmp]# grep -oP '\b[-\w]+@([\w-]+\.){1,}[a-zA-Z]{2,3}\b' mail.txt _lkdfljdlf@qq.com 348938@qq.com dkjfkd@chinamobile.com djdjkf@163.com dkjfkdjf@139.com 384939@139.com djfdk@Huawei.com dkfjdkf@cisco.com 3349@hao123.cn djk@163.cn dkj_21@qq.com dkjf_12j@zz.com [root@zz tmp]# cat mail.txt _lkdfljdlf@qq.com 34*348938@qq.com dkjfkd@chinamobile.com djdjkf@163.com dkjfkdjf@139.com 384939@139.com djfdk@Huawei.com dkfjdkf@cisco.com 3349@hao123.cn dklfdjlf.cn djk@163.cn 343kjk3 d9fdm @@@ djfkdj@ @fjkd @dfldm 2@djkf dfjldf@zz dkjfkd@czm @djfkdc*m dkj_21@qq.com dkjf_12j@zz.com
11、查找/var目录下属主为root,且属组为mail的所有文件或目录;
[root@zz network-scripts]# find /var -user root -a -group mail -ls 1179651 4 drwxrwxr-x 2 root mail 4096 Jun 15 22:10 /var/spool/mail
12、查找当前系统上没有属主或属组的文件;进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;
[root@zz network-scripts]# find /home \( -nouser -o -nogroup \) -ls 389387 4 drwx------ 3 505 505 4096 Jun 15 22:10 /home/user1 389389 4 -rw-r--r-- 1 505 505 176 May 11 07:21 /home/user1/.bash_profile 389388 4 -rw-r--r-- 1 505 505 124 May 11 07:21 /home/user1/.bashrc 389390 4 -rw-r--r-- 1 505 505 18 May 11 07:21 /home/user1/.bash_logout 389391 4 drwxr-xr-x 2 505 505 4096 Nov 12 2010 /home/user1/.gnome2 [root@zz network-scripts]# find /home -nouser -a -nogroup -a -atime -3 -ls 389387 4 drwx------ 3 505 505 4096 Jun 15 22:10 /home/user1 389389 4 -rw-r--r-- 1 505 505 176 May 11 07:21 /home/user1/.bash_profile 389388 4 -rw-r--r-- 1 505 505 124 May 11 07:21 /home/user1/.bashrc 389390 4 -rw-r--r-- 1 505 505 18 May 11 07:21 /home/user1/.bash_logout 389391 4 drwxr-xr-x 2 505 505 4096 Nov 12 2010 /home/user1/.gnome2
13、查找/etc目录下所有用户都有写权限的文件;
[root@zz user1]# find /etc -perm -222 -ls 786529 0 lrwxrwxrwx 1 root root 10 Jun 14 20:39 /etc/rc1.d -> rc.d/rc1.d 786689 0 lrwxrwxrwx 1 root root 16 Jun 14 20:37 /etc/ssl/certs -> ../pki/tls/certs 787110 0 lrwxrwxrwx 1 root root 15 Jun 14 20:39 /etc/rc.sysinit -> rc.d/rc.sysinit 787111 0 lrwxrwxrwx 1 root root 10 Jun 14 20:39 /etc/rc0.d -> rc.d/rc0.d 787158 0 lrwxrwxrwx 1 root root 15 Jun 14 20:39 /etc/rc.d/rc1.d/K75netfs -> ../init.d/netfs 788058 0 lrwxrwxrwx 1 root root 14 Jun 14 20:42 /etc/rc.d/rc1.d/K99rngd -> ../init.d/rngd 787271 0 lrwxrwxrwx 1 root root 17 Jun 14 20:39 /etc/rc.d/rc1.d/K86nfslock -> ../init.d/nfslock 787389 0 lrwxrwxrwx 1 root root 16 Jun 14 20:40 /etc/rc.d/rc1.d/K76ypbind -> ../init.d/ypbind 787008 0 lrwxrwxrwx 1 root root 18 Jun 14 20:39 /etc/rc.d/rc1.d/K92iptables -> ../init.d/iptables 787183 0 lrwxrwxrwx 1 root root 19 Jun 14 20:39 /etc/rc.d/rc1.d/S26udev-post -> ../init.d/udev-post 787404 0 lrwxrwxrwx 1 root root 15 Jun 14 20:40 /etc/rc.d/rc1.d/K86cgred -> ../init.d/cgred 787422 0 lrwxrwxrwx 1 root root 20 Jun 14 20:40 /etc/rc.d/rc1.d/K01certmonger -> ../init.d/certmonger 788250 0 lrwxrwxrwx 1 root root 15 Jun 14 21:09 /etc/rc.d/rc1.d/K15httpd -> ../init.d/httpd 787172 0 lrwxrwxrwx 1 root root 20 Jun 14 20:39 /etc/rc.d/rc1.d/K89netconsole -> ../init.d/netconsole 787045 0 lrwxrwxrwx 1 root root 15 Jun 14 20:39 /etc/rc.d/rc1.d/K89rdisc -> ../init.d/rdisc 787339 0 lrwxrwxrwx 1 root root 13 Jun 14 20:40 /etc/rc.d/rc1.d/K05atd -> ../init.d/atd 787963 0 lrwxrwxrwx 1 root root 26 Jun 14 20:41 /etc/rc.d/rc1.d/S25blk-availability -> ../init.d/blk-availability 788376 0 lrwxrwxrwx 1 root root 15 Jun 14 21:22 /etc/rc.d/rc1.d/K50snmpd -> ../init.d/snmpd
14、查找/etc目录下大于1M,且类型为普通文件的所有文件;
[root@zz user1]# find /etc -size +1M -a -type f -exec ls -lht {} \; -rw-r--r--. 1 root root 8.1M Jun 14 22:21 /etc/selinux/targeted/policy/policy.24 -rw-r--r--. 1 root root 8.1M Jun 14 22:21 /etc/selinux/targeted/modules/active/policy.kern
15、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;
[root@zz user1]# find /etc/init.d -perm -113 -ls 786520 0 lrwxrwxrwx 1 root root 11 Jun 14 20:35 /etc/init.d -> rc.d/init.d
16、查找/usr目录下不属于root、bin或hadoop的文件;
[root@zz user1]# find /usr -not \( -user root -o -user bin -o -user hadop \) -ls 524326 12 -rwsr-xr-x 1 abrt abrt 10296 May 12 04:43 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache 934629 4 drwxr-xr-x 10 mysql mysql 4096 Jun 14 21:21 /usr/share/mysql-test 8784 4 drwxr-xr-x 4 mysql mysql 4096 Jun 14 21:20 /usr/share/mysql-test/lib 9100 4 drwxr-xr-x 3 mysql mysql 4096 Jun 14 21:20 /usr/share/mysql-test/lib/v1 9107 8 -rw-r--r-- 1 mysql mysql 5758 May 11 14:31 /usr/share/mysql-test/lib/v1/mtr_io.pl
17、查找/etc/目录下至少有一类用户没有写权限的文件;
[root@zz tmp]# find /etc/ -not -perm -222 -ls 786434 12 drwxr-xr-x 113 root root 12288 Jun 16 03:16 /etc/ 787033 4 drwxr-xr-x 2 root root 4096 Jun 14 20:39 /etc/iproute2 787036 4 -rw-r--r-- 1 root root 317 May 11 03:01 /etc/iproute2/rt_protos 787038 4 -rw-r--r-- 1 root root 92 May 11 03:01 /etc/iproute2/rt_scopes 787037 4 -rw-r--r-- 1 root root 112 May 11 03:01 /etc/iproute2/rt_realms 787035 4 -rw-r--r-- 1 root root 442 May 11 03:01 /etc/iproute2/rt_dsfield 787034 4 -rw-r--r-- 1 root root 59 May 11 03:01 /etc/iproute2/ematch_map 787039 4 -rw-r--r-- 1 root root 87 May 11 03:01 /etc/iproute2/rt_tables 786438 4 drwxr-xr-x 2 root root 4096 Jun 14 21:22 /etc/rpm 786578 4 -rw-r--r-- 1 root root 1022 Oct 1 2015 /etc/rpm/macros.perl 786726 12 -rw-r--r-- 1 root root 8802 May 11 02:27 /etc/rpm/macros.jpackage 788391 4 -rw-r--r-- 1 root root 270 May 11 05:42 /etc/rpm/macros.php 788092 4 -rw-r--r-- 1 root root 297 Aug 19 2013 /etc/rpm/macros.prelink 788367 4 -rw-r--r-- 1 root root 1427 May 11 06:42 /etc/rpm/macros.pear 786980 4 -rw-r--r-- 1 root root 66 May 19 03:47 /etc/rpm/macros.dist 786764 8 -rw-r--r-- 1 root root 4940 Feb 22 2013 /etc/man.config 786688 4 drwxr-xr-x 2 root root 4096 Jun 14 20:37 /etc/ssl 788113 4 drwxr-x--- 2 root root 4096 May 11 07:13 /etc/sudoers.d 786439 4 drwxr-xr-x 2 root root 4096 Jun 15 17:24 /etc/modprobe.d 787724 0 -rw-r--r-- 1 root root 0 Jun 15 17:24 /etc/modprobe.d/network.conf 786662 4 -rw-r--r-- 1 root root 382 Jul 24 2015 /etc/modprobe.d/dist-alsa.conf 787985 4 -rw-r--r-- 1 root root 93 May 11 14:32 /etc/modprobe.d/libcxgb4.conf 787987 4 -rw-r--r-- 1 root root 1007 May 11 14:32 /etc/modprobe.d/mlx4.conf 787984 4 -rw-r--r-- 1 root root 93 May 11 14:32 /etc/modprobe.d/libcxgb3.conf 787986 4 -rw-r--r-- 1 root root 510 May 11 14:32 /etc/modprobe.d/libmlx4.conf 787955 4 -rw-r--r-- 1 root root 30 Mar 20 2015 /etc/modprobe.d/openfwwf.conf 786663 4 -rw-r--r-- 1 root root 473 Jul 24 2015 /etc/modprobe.d/dist-oss.conf 786664 8 -rw-r--r-- 1 root root 5850 Jul 24 2015 /etc/modprobe.d/dist.conf 786712 4 -rw-r--r-- 1 root root 884 May 11 18:04 /etc/modprobe.d/blacklist.conf 786442 4 -rw-r--r-- 1 root root 52 Jun 14 20:34 /etc/modprobe.d/anaconda.conf
18、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;
[root@zz user1]# find /etc -ctime -7 -a -not \( -user root -o -user hadop \) -ls 788439 4 drwxr-x--- 2 apache apache 4096 Jun 15 10:40 /etc/zabbix/web 787599 4 -rw-r--r-- 1 apache apache 441 Jun 15 10:40 /etc/zabbix/web/zabbix.conf.php [root@zz user1]# date Thu Jun 16 01:12:30 CST 2016
总结:由于前面这些“基础行政”题没有学得扎实,并没有经常温故做好总结,导致学了后面的内容,前面的知识基本忘光了。。。。再来做前面的题目非常吃力,将会抽出时间对这些正则表达式、测试条件、vim操作、shell脚本多加练习;
原创文章,作者:Net21_仲樂,如若转载,请注明出处:http://www.178linux.com/25542
评论列表(2条)
写的很好,排版也很棒,加油
@马哥教育:3Q