您的位置:首页 > 运维架构 > Linux

【Linux基础】第五周作业

2016-09-05 14:44 330 查看
1、显示当前系统上root、fedora或user1用户的默认shell;
#egrep ‘^(root|fedora|user1)’/etc/passwd|cut -d: -f1,7

[root@localhost ~]# egrep '^(root|lanin)' /etc/passwd|cut -d: -f1,7

root:/bin/bash

lanin:/bin/bash
#awk -F:‘/root|fedora|user1/{print $1”  ”,$7}’ /etc/passwd
sed -n ‘/root|fedora|user1/p’/etc/passwd |cut -d: -f1,7
2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();
egrep -o ‘\<[[:alpha:]]+\>\(\)’/etc/rc.d/init.d/functions

[root@localhost ~]# egrep -o  '\<[[:alpha:]]+\>\(\)' /etc/rc.d/init.d/functions

checkpid()
daemon()
killproc()
pidfileofproc()
pidofproc()
status()
success()
failure()
passed()
warning()
action()
strstr()
confirm()
3、使用echo命令输出一个绝对路径,使用grep取出其基名;扩展:取出其路径名路径名:
#echo /etc/sysconfig/network-scripts/ifcfg-eth0|grep  -o ‘^/.*/’

[root@localhost ~]# echo /etc/sysconfig/network-scripts/route-eth0 |grep -o '^/.*/'

/etc/sysconfig/network-scripts/
基名:
[root@localhost ~]# echo /etc/sysconfig/network-scripts/ifcfg-eth0|grep -o  '[^/]\+$'

ifcfg-eth0
4、找出ifconfig命令结果中的1-255之间数字;
#ifconfig|egrep -o '[1-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-9]'
5、挑战题:写一个模式,能匹配合理的IP地址;
[root@localhost ~]# ifconfig|egrep -o '(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-9])\.){3}[0-9]{1,3}'192.168.1.159192.168.1.255255.255.255.0127.0.0.1255.0.0.0
6、挑战题:写一个模式,能匹配出所有的邮件地址;
'[[:alnum:]]+@[[:alnum:]]+(\.[a-z]+){1,}'[root@localhost ~]# egrep -o  '[[:alnum:]]+@[[:alnum:]]+(\.[a-z]+){1,}' /tmp/mailtestlanin@qq.comlanlin789@foxmail.com1170182749@qq.comlxy021341125@163.comlanlin3101@gmail.comlxy021341125@sina.com.cnlanin@163.cc.com.cn.edu
7、查找/var目录下属主为root,且属组为mail的所有文件或目录;
#find /var/ -user root -a -group mail[root@localhost ~]# find /var/ -user root -a -group mail -ls652520    4 drwxrwxr-x   2 root     mail         4096 Sep  5 03:48 /var/spool/mail664453    4 -rw-------   1 root     mail         4017 Sep  5 03:48 /var/spool/mail/root
8、查找当前系统上没有属主或属组的文件;进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;
#find / -nouser -o -nogroup#find / -nouser -o -nogroup   -atime -3
9、查找/etc目录下所有用户都有写权限的文件;
[root@localhost ~]# find /etc/ -perm -222/etc/rc3.d/etc/vmware-tools/icu/etc/vmware-tools/plugins/etc/rc.d/rc3.d/K10saslauthd/etc/rc.d/rc3.d/K01smartd
10、查找/etc目录下大于1M,且类型为普通文件的所有文件;
[root@localhost ~]# find /etc/ -size +1M -type f/etc/logrotate.conf/etc/ppp/chap-secrets/etc/ppp/firewall-standalone... ...
老师,请问根据题目的意思这样能行吗?ls -l /etc/ | grep '^-' | awk '{if($5>1024) print $0}'ll /etc/|awk '{if($5>1024)print$0}' |grep '^-' 11、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;
[root@localhost ~]# find /etc/init.d/ -perm -113 -ls397852   16 -rwx-wx-wx   1 root     root        12709 Sep  4 08:17 /etc/init.d/rdmacopy
同上一问,以下这种只匹配了一级目录中的所有文件和目录,不包括子目录及其文件,就是单纯的文本筛选:ll /etc/init.d |grep ‘^...x..x.wx’12、查找/usr目录下不属于root、bin或hadoop的文件;
# find /usr/ ! -user root -a ! -user bin -a ! -user hadoop# find /usr/ -not \( -user root -o -user bin -o -user hadoop \)
13、查找/etc/目录下至少有一类用户没有写权限的文件;
#find /etc/ ! -perm -222[root@localhost ~]# find /etc/ ! -perm -222 -ls392462    4 -rw-r--r--   1 root     root          203 Mar 23 10:03 /etc/alsa/alsactl.conf397775    4 -rw-r--r--   1 root     root          537 May 11 03:39 /etc/alsa/pulse-default.conf395474    4 -rw-r--r--   1 root     root         3384 May 10 21:37 /etc/drirc395467    4 drwxr-xr-x   2 root     root         4096 Aug 31 00:52 /etc/plymouth395468    4 -rw-r--r--   1 root     root           72 Aug 11  2014 /etc/plymouth/plymouthd.conf
14、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;
# find /etc/ -mtime -7 -not -user root -not -user hadoop# find /etc/ -mtime -7 -not \( -user root -o -user hadoop\)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux 基础