N26-第五周博客作业

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

[root@promote home]# grep -E ‘^(root|fedora|user1)’ /etc/passwd |
cut -d : -f7

/bin/bash

/bin/bash

/bin/bash

[root@promote home]#

注:仅egrep支持(a|b)这种模式

 

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

[root@VM_221_40_centos ~]# grep -o
“\<[_[:alpha:]]\+\>(.*)” /etc/rc.d/init.d/functions

checkpid()

__pids_var_run()

__pids_pidof()

daemon()

killproc()

if($1!~/^[0-9.]+[smhd]?$/) exit 1;d=$1~/s$|^[0-9.]*$/?1:$1~/m$/?60:$1~/h$/?60*60:$1~/d$/?24*60*60:-1;if(d==-1)
exit 1;delay+=d*$1} END {printf(“%d”,delay+0.5)}’)

pidfileofproc()

pidofproc()

status()

echo_success()

echo_failure()

echo_passed()

echo_warning()

update_boot_stage()

success()

failure()

passed()

warning()

action()

strstr()

is_ignored_file()

is_true()

is_false()

apply_sysctl()

[root@VM_221_40_centos ~]#

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

[root@VM_221_40_centos
init.d]# echo $PWD | grep -o “[^/]\+$”

init.d

[root@VM_221_40_centos
init.d]#

 

 

 扩展:取出其路径名

[root@VM_221_40_centos init.d]# echo $PWD | grep -o
“^/.*/”

/etc/rc.d/

[root@VM_221_40_centos init.d]#

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

[root@VM_221_40_centos init.d]# ifconfig | grep -E -o
“\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>”

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

grep -E
“\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.(\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){2}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])”
/tmp/ip

 

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

邮箱地址中用户名可以是数字、字母(分大小写)、下划线。

grep -Eo “\<[a-z,A-Z,0-9,_-]+@[A-Z,a-z,0-9,-]+\.[A-Z,a-z,0-9]{2,}\>”
/tmp/mail

或者

grep -o
“\<[a-z,A-Z,0-9,_]\+@[A-Z,a-z,0-9,-]\+\.[A-Z,a-z,0-9]\{2,\}\>”
/tmp/mail

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

[root@VM_221_40_centos ~]# find /var -user root -group mail -ls

 24631    4 drwxrwxr-x   2 root     mail         4096 May 15 00:22
/var/spool/mail

[root@VM_221_40_centos ~]#

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

[root@VM_221_40_centos ~]# find /home -nouser -a -nogroup -ls | more

278530    4 drwx——   3 1000     1000         4096 May 15 00:23
/home/gentoo

278534    4 -rw——-   1 1000     1000          126 May 15 02:02
/home/gentoo/.bash_hi

story

278535    4 drwxrwxr-x   2 1000     1000         4096 May 15 00:23
/home/gentoo/gen

278531    4 -rw-r–r–   1 1000     1000          231 Aug  3  2016
/home/gentoo/.bashrc

278532    4 -rw-r–r–   1 1000     1000           18 Aug  3  2016
/home/gentoo/.bash_lo

gout

278533    4 -rw-r–r–   1 1000     1000          193 Aug  3  2016
/home/gentoo/.bash_pr

ofile

[root@VM_221_40_centos ~]#

 进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;

[root@VM_221_40_centos ~]# find /home
-nouser -a -nogroup -a -ctime -3 -ls | more

278530    4 drwx——   3 1000     1000         4096 May 15 00:23 /home/gentoo

278534    4 -rw——-   1 1000     1000          126 May 15 02:02
/home/gentoo/.bash_hi

story

278535    4 drwxrwxr-x   2 1000     1000         4096 May 15 00:23 /home/gentoo/gen

278531    4 -rw-r–r–   1 1000     1000          231 Aug  3  2016
/home/gentoo/.bashrc

278532    4 -rw-r–r–   1 1000     1000           18 Aug  3  2016
/home/gentoo/.bash_lo

gout

278533    4 -rw-r–r–   1 1000     1000          193 Aug  3  2016
/home/gentoo/.bash_pr

ofile

[root@VM_221_40_centos ~]#

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

[root@VM_221_40_centos ~]# find ./ -perm -222 –ls

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

[root@VM_221_40_centos
~]# find /etc -size +1M -type f –ls

 

原创文章,作者:lixinkuan,如若转载,请注明出处:http://www.178linux.com/75770

赞 (0)
lixinkuanlixinkuan
上一篇 2017-05-15 16:38
下一篇 2017-05-15 19:27

相关推荐

  • 第三周小练习

    1. 列出当前系统上所有已经登陆的用户的用户名,注意,同一个用户登陆多次,则显示一次即可 who -u|grep -o "^[[:alnum:]]*\>"|uniq 2. 取出最后登陆到当前系统的用户信息 who|tail -n1 3. 取出当前系统上被用户当作其默认shell的最多的那个sh…

    Linux干货 2016-11-21
  • 集中管理利器-puppet快速入门-下

    Puppet配置 1.    文件管理 file 文件服务器写法: /etc/puppet/ fileserver.conf 定义 [files] path /tmp/files  ## puppet数据存放目录 =è后面远程备份实战会用到 allow *.example.com 实战1: 备份master机…

    Linux干货 2015-05-07
  • Linux上实现rsyslog+mysql+loganalyz进行日志收集

    在我们的运维工作中,常常会对系统上的日志进行收集,手动管理少量的几台服务器的日志收集没有太大难度,但是企业当中批量的管理成千上万台服务器的时候,这时候想一台台的收集日志未免太浪费时间了,这时候我们需要一个批量管理日志的系统来解决这一难题,今天我给大家带来的使用 1、syslog介绍       &n…

    Linux干货 2016-10-24
  • OSI参考模型与TCP/IP参考模型的比较

    OSI参考模型与TCP/IP参考模型的比较 OSI参考模型 OSI参考模型是ISO的建议,它是为了使各层上的协议国际标准化而发展起来的。OSI参考模型全称是开放系统互连参考模型(Open System Interconnection Reference Model)。这一参考模型共分为七层:物理层、数据链路层、网络层、传输层、会话层、表示层和应用层。 物理层…

    Linux干货 2017-05-07
  • 集中练习8-bash脚本及系统启动

    集中练习8-bash脚本及系统启动

    2017-12-06

评论列表(1条)

  • luoweiro
    luoweiro 2017-06-26 23:05

    进度要跟上了,加油。