Linux基础第五周作业
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux基础第五周作业相关的知识,希望对你有一定的参考价值。
1、显示当前系统上root、fedora或user1用户的默认shell;
#egrep ‘^(root|fedora|user1)’/etc/passwd|cut -d: -f1,7 [[email protected] ~]# 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 [[email protected] ~]# 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 ‘^/.*/’ [[email protected] ~]# echo /etc/sysconfig/network-scripts/route-eth0 |grep -o ‘^/.*/‘ /etc/sysconfig/network-scripts/
基名:
[[email protected] ~]# 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地址;
[[email protected] ~]# 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.159 192.168.1.255 255.255.255.0 127.0.0.1 255.0.0.0
6、挑战题:写一个模式,能匹配出所有的邮件地址;
‘[[:alnum:]][email protected][[:alnum:]]+(\.[a-z]+){1,}‘ [[email protected] ~]# egrep -o ‘[[:alnum:]][email protected][[:alnum:]]+(\.[a-z]+){1,}‘ /tmp/mailtest [email protected] [email protected] [email protected] [email protected] [email protected] [email protected] [email protected]
7、查找/var目录下属主为root,且属组为mail的所有文件或目录;
#find /var/ -user root -a -group mail [[email protected] ~]# find /var/ -user root -a -group mail -ls 652520 4 drwxrwxr-x 2 root mail 4096 Sep 5 03:48 /var/spool/mail 664453 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目录下所有用户都有写权限的文件;
[[email protected] ~]# 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,且类型为普通文件的所有文件;
[[email protected] ~]# 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/目录下,所有用户都有执行权限,且其它用户有写权限的文件;
[[email protected] ~]# find /etc/init.d/ -perm -113 -ls 397852 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 [[email protected] ~]# find /etc/ ! -perm -222 -ls 392462 4 -rw-r--r-- 1 root root 203 Mar 23 10:03 /etc/alsa/alsactl.conf 397775 4 -rw-r--r-- 1 root root 537 May 11 03:39 /etc/alsa/pulse-default.conf 395474 4 -rw-r--r-- 1 root root 3384 May 10 21:37 /etc/drirc 395467 4 drwxr-xr-x 2 root root 4096 Aug 31 00:52 /etc/plymouth 395468 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\)
本文出自 “11460225” 博客,请务必保留此出处http://11470225.blog.51cto.com/11460225/1846407
以上是关于Linux基础第五周作业的主要内容,如果未能解决你的问题,请参考以下文章