第五周:作业内容
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第五周:作业内容相关的知识,希望对你有一定的参考价值。
显示当前系统上root、fedora或user1用户的默认shell;
[[email protected] /]# grep -E"^root\>|^fedora\>|^user1\>" /etc/passwd root:x:0:0:root:/root:/bin/bash fedora:x:1022:1024::/home/fedora:/bin/bash user1:x:1023:1025::/home/user1:/bin/bash [[email protected] /]# grep –E "^root\>|^fedora\>|^user1\>"/etc/passwd | cut -d: -f1,7 root:/bin/bash fedora:/bin/bash user1:/bin/bash
找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();
[[email protected] /]# grep -o "[[:alpha:]]\+()"/etc/rc.d/init.d/functions checkpid() run() pidof() daemon() killproc() pidfileofproc() pidofproc() status() success() failure() passed() warning() stage() success() failure() passed() warning() action() strstr() file() true() false() sysctl()
3、使用echo命令输出一个绝对路径,使用grep取出其基名;
扩展:取出其路径名
扩展:取出其路径名
[[email protected] mytest1]# echo"/tmp/mytest1/ppp" |grep -Eo "[^/]+/?$" Ppp
取出其路径名
[[email protected] mytest1]# echo"/tmp/mytest1/ppp" | grep -o "/[[:alpha:]]\+.*/" /tmp/mytest1/
找出ifconfig命令结果中的1-255之间数字;
[[email protected] mytest1]# ifconfig em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.252 netmask255.255.255.0 broadcast 192.168.1.255 inet6 fe80::7a2b:cbff:fe3f:710d prefixlen 64 scopeid0x20<link> ether 78:2b:cb:3f:71:0d txqueuelen 1000 (Ethernet) RX packets 4506052958 bytes381632573878 (355.4 GiB) RX errors 0 dropped 22637 overruns 0 frame 0 TX packets 15272610830 bytes979169669462 (911.9 GiB) TX errors 0 dropped 0 overruns0 carrier 0 collisions 0
[[email protected] mytest1]# ifconfig | egrep -o"\<[1-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>" 192 168 1 252 255 255 255 192 168 1 255 64 78 71 4 9 192 168 1 253 255 255 255 192 168 1 255 64 78 71 78 71 11 78 71 13 73 127 1 255 1 128 16 3 16 3
5、挑战题:写一个模式,能匹配合理的IP地址;
#ifconfig |egrep -o"(\<[1-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>)\.(\<[0-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>)\.(\<[0-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>).(\<[0-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>)"
6、挑战题:写一个模式,能匹配出所有的邮件地址;
[[email protected] logs]# echo "[email protected]" | grep -o "\<[0-9a-zA-Z]\+.*@[0-9a-z]\+\.[[:alpha:]]\+\>"
7、查找/var目录下属主为root,且属组为mail的所有文件或目录;
[[email protected] logs]# find /var -userroot -group mail -ls 393300 4 drwxrwxr-x 2 root mail 4096 Jul 27 11:09 /var/spool/mail
8、查找当前系统上没有属主或属组的文件;
进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;
[[email protected] logs]# find / \( -nouser-o -nogroup \) -a -atime 3 -ls find: ‘/proc/1349/task/1349/fd/6’: No suchfile or directory find: ‘/proc/1349/task/1349/fdinfo/6’: Nosuch file or directory find: ‘/proc/1349/fd/6’: No such file ordirectory find: ‘/proc/1349/fdinfo/6’: No such fileor directory
9、查找/etc目录下所有用户都有写权限的文件;
[[email protected] logs]# cd /etc [[email protected] etc]# find /etc -perm -222 -ls 658871 0 lrwxrwxrwx 1 root root 14 Jun 18 16:50/etc/sysctl.d/99-sysctl.conf -> ../sysctl.conf 658524 0 lrwxrwxrwx 1 root root 59 Nov 21 2014/etc/fonts/conf.d/10-scale-bitmap-fonts.conf ->/usr/share/fontconfig/conf.avail/10-scale-bitmap-fonts.conf 658540 0 lrwxrwxrwx 1 root root 50 Nov 21 2014 /etc/fonts/conf.d/90-synthetic.conf-> /usr/share/fontconfig/conf.avail/90-synthetic.conf 658525 0 lrwxrwxrwx 1 root root 58 Nov 21 2014 /etc/fonts/conf.d/20-unhint-small-vera.conf-> /usr/share/fontconfig/conf.avail/20-unhint-small-vera.conf 658538 0 lrwxrwxrwx 1 root root 48 Nov 21 2014 /etc/fonts/conf.d/69-unifont.conf ->/usr/share/fontconfig/conf.avail/69-unifont.conf
10、查找/etc目录下大于1M,且类型为普通文件的所有文件;
[[email protected] etc]# find /etc -size+1M -a -type f -ls 791481 6824 -r--r--r-- 1 root root 6984832 Sep 5 15:10 /etc/udev/hwdb.bin 793843 3700 -rw-r--r-- 1 root root 3786319 Jun 18 16:51/etc/selinux/targeted/policy/policy.29 659990 1308 -rw------- 1 root root 1335701 Jun 18 16:51/etc/selinux/targeted/contexts/files/file_contexts.bin
11、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;
#find /etc/init.d/ -perm -113 –ls
12、查找/usr目录下不属于root、bin或hadoop的文件;
#find /usr -not -user root -a -not -userbin –a -not -user hadoop
13、查找/etc/目录下至少有一类用户没有写权限的文件;
# find /etc -not –perm 222
14、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;
#find /etc/ -mtime -7 -a -not -user root -a-not -user hadoop
本文出自 “9099360” 博客,请务必保留此出处http://9109360.blog.51cto.com/9099360/1846463
以上是关于第五周:作业内容的主要内容,如果未能解决你的问题,请参考以下文章