linux 就业班 网络班 不同,马哥Linux网络班作业(5)(示例代码)

1、显示当前系统上root、fedora或user1用户的默认shell;

答:[[email protected] ~]# egrep ‘^(root|user1)\>‘ /etc/passwd | cut -d: -f7

/bin/bash

/bin/bash

2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();

答:[[email protected] ~]# grep ‘\()‘ /etc/rc.d/init.d/functions

checkpid() {

daemon() {

killproc() {

pidfileofproc() {

pidofproc() {

status() {

success() {

failure() {

passed() {

warning() {

action() {

strstr() {

3、使用echo命令输出一个绝对路径,使用grep取出其基名;

扩展:取出其路径名

答:#基名

[[email protected] ~]# echo "/tmp/log/txt" | egrep -o "[^/]+/?$"

txt

#路径名

[[email protected] ~]# echo "/tmp/log/txt" | egrep -o ".*/"

/tmp/log/

4、找出ifconfig命令结果中的1-255之间数字;

答:[[email protected] ~]# ifconfig | egrep -ow ‘\‘

10

11

255

255

255

10

255

64

29

4

171

73

127

1

255

1

128

5、挑战题:写一个模式,能匹配合理的IP地址;

答:egrep "(\\.){3}\"

注释:

[0,1]?[0-9]?[0-9]  :匹配0-199

2[0-4][0-9]  :匹配200-249

25[0-5]  :匹配250-255

([0,1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])  :匹配0-255

6、挑战题:写一个模式,能匹配出所有的邮件地址;

答:[[email protected] ~]# egrep "^([[:alpha:]]|[0-9]|\_)*@([[:alpha:]]|[0-9])*.com$"

7、查找/var目录下属主为root,且属组为mail的所有文件或目录;

答:[[email protected] ~]# find /var -user root -group mail

/var/spool/mail

8、查找当前系统上没有属主或属组的文件;

答:[[email protected] ~]# find / -nouser -a -nogroup

find: ‘/proc/2883/task/2883/fd/6’: 没有那个文件或目录

find: ‘/proc/2883/task/2883/fdinfo/6’: 没有那个文件或目录

find: ‘/proc/2883/fd/6’: 没有那个文件或目录

find: ‘/proc/2883/fdinfo/6’: 没有那个文件或目录

进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;[[email protected] ~]# find / -nouser -nogroup -mtime -3

find: ‘/proc/2890/task/2890/fd/6’: 没有那个文件或目录

find: ‘/proc/2890/task/2890/fdinfo/6’: 没有那个文件或目录

find: ‘/proc/2890/fd/6’: 没有那个文件或目录

find: ‘/proc/2890/fdinfo/6’: 没有那个文件或目录

9、查找/etc目录下所有用户都有写权限的文件;

答:[[email protected] ~]# find /etc -perm -222 -ls

134320260    0 lrwxrwxrwx   1 root     root           17 8月 14 16:45 /etc/mtab -> /proc/self/mounts

67332427    0 lrwxrwxrwx   1 root     root           49 8月 14 16:45 /etc/pki/tls/certs/ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem

67332428    0 lrwxrwxrwx   1 root     root           55 8月 14 16:45 /etc/pki/tls

....略

10、查找/etc目录下大于1M,且类型为普通文件的所有文件;

答:[[email protected] ~]# find /etc -size +1M -type f -exec ls -lh {} \;

-r--r--r--. 1 root root 6.7M 8月  14 16:50 /etc/udev/hwdb.bin

-rw-r--r--. 1 root root 3.7M 11月 21 2015 /etc/selinux/targeted/policy/policy.29

11、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;

答:[[email protected] ~]# find /etc/init.d -perm -113 -ls

134356480    0 lrwxrwxrwx   1 root     root           11 8月 14 16:45 /etc/init.d -> rc.d/init.d

12、查找/usr目录下不属于root、bin或hadoop的文件;

答:[[email protected] ~]# find /usr -not \( -user root -o -user bin -o -user hadoop \) -ls

134672278    0 drwx------   2 polkitd  root            6 6月 10  2014 /usr/share/polkit-1/rules.d

13、查找/etc/目录下至少有一类用户没有写权限的文件;

答:[[email protected] ~]#find /etc -not -perm 222 -ls

14、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;

答:[[email protected] ~]# find /etc -mtime -7 -a -not -user root -a -not -user hadoop

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值