N26-第五周博客作业

一、显示当前系统上rootfedorauser1用户的默认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

相关推荐

  • 新手上路,多多担待,分享linux的ls 常用选项

    ls 命令   ls[OPTION]…[FILE]….选项 和 参数可有可无。 定义:显示指定路径下的文件列表。  -a: 全拼是all,所有的意思,ls  -a能显示出所有的文件,包括隐藏的。点开头和..开头的隐藏文件都能看见。  -l:后跟文件 可以查看文件的大小,和权限(一般用户都有读的权…

    2017-05-21
  • Ansible安装及简单使用

    简介: ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架。主要包…

    Linux干货 2016-08-07
  • Centos6上安装cobbler及cobbler常见参数详解

    前言 Cobbler是一个自动化和简化系统安装的工具,通过使用网络引导来控制和启动安装。Cobbler的特性包括存储库镜像、Kickstart模板和连接电源管理系统。使用Cobbler之前需要先了解下PXE和Kickstart的基本原理,文章包含了Cobbler工作原理和Cobbler部署实践两部分内容,交叉关联性的内容还是蛮多的,遇到报错也不要怕,都会一步…

    Linux干货 2016-11-11
  • Trie树:应用于统计和排序

    1. 什么是trie树 1.Trie树 (特例结构树)         Trie树,又称单词查找树、字典树,是一种树形结构,是一种哈希树的变种,是一种用于快速检索的多叉树结构。典型应用是用于统计和排序大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计。它的优点是:最大限度地减少…

    Linux干货 2015-04-08
  • Linux学习笔记(第三篇)

    N21_Keen_第三周博客 1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 who | cut -d " " -f 1 | sort -u 2、取出最后登录到当前系统的用户的相关信息。 last…

    Linux干货 2016-08-15
  • Linux的用户组和权限(二)

      一、1.passwd 设置密码(类似usermod的用法)       passwd[OPTIONS] UserName:          修改指定用户的密码,仅root用户有权限       …

    Linux干货 2016-08-08

评论列表(1条)

  • luoweiro
    luoweiro 2017-06-26 23:05

    进度要跟上了,加油。