第五周 练习

1、显示当前系统上rootfedorauser1用户的默认shell

1.  egrep "^(root|user1|fedora)" /etc/passwd|cut d: f7

 

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

1.  egrep "^[[:alpha:]]+\(\)" /etc/rc.d/init.d/functions

 

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

1.  ~]#echo "/etc/init.d/" | grep oE "[^/]+/?$"

2.  init.d/

3.  扩展:取出其路径名

4.  ~]#echo "/etc/init.d/" | grep o "/[A-Za-z0-9]\+.*/"

5.  /etc/init.d/

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

1.  ifconfig | egrep "\<[1-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>"

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

1.  ifconfig | egrep "(\<[1-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>)\.(\<[0-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>)\.(\<[0-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>).(\<[0-9]\>|\<[1-9][0-9]\>|\<[1][0-9][0-9]\>|\<[2][0-4][0-9]\>|\<[2][5][0-5]\>)"

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

1.  ~]# echo "My Email:jinjianping@qq.com" | grep "\<[[:alpha:]]\+.*@[0-9a-z]\+\.[[:alpha:]]\+\>"

2.  My Email:jinjianping@qq.com

 

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

1.  ~]# find /var user root group mail ls

2.  134311219    4 drwxrwxrx   2 root     mail         4096 Nov 24 15:32 /var/spool/mail

3.  135420759    4 rw——-   1 root     mail         1355 Nov  9 15:45 /var/spool/mail/root

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

1.  ~]#  find / \( nouser o nogroup \) ls

2.  find: ‘/proc/5594/task/5594/fd/6’: No such file or directory

3.  find: ‘/proc/5594/task/5594/fdinfo/6’: No such file or directory

4.  find: ‘/proc/5594/fd/6’: No such file or directory

5.  find: ‘/proc/5594/fdinfo/6’: No such file or directory

6.  135441653    0 rwrw—-   1 3005     mail            0 Nov  5 18:21 /var/spool/mail/gentoo

7.  find: File system loop detected; ‘/home1 is part of the same file system loop as ‘/’. 

 

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

1.  ~]# find /  atime 3 \( nouser o nogroup  \) ls

2.  find: ‘/proc/5601/task/5601/fd/6’: No such file or directory

3.  find: ‘/proc/5601/task/5601/fdinfo/6’: No such file or directory

4.  find: ‘/proc/5601/fd/6’: No such file or directory

5.  find: ‘/proc/5601/fdinfo/6’: No such file or directory

6.  find: File system loop detected; ‘/home1 is part of the same file system loop as ‘/’.

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

 

1.  find /etc perm 222 ls

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

 

1.  find /etc   type f size +1M ls

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

 

1.  find /etc/init.d/ type f  perm 113

12、查找/usr目录下不属于rootbinhadoop的文件;

1.   find /usr ! \( user root o user bin o user hadoop \) ls 

 

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

1.  find /etc/ \( ! perm +200 o ! perm +020 o ! perm +002 \) ls

 

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

1.  find /etc \( mtime 7 ! user root a ! user hadoop \) ls

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

(2)
N24_JJPN24_JJP
上一篇 2016-11-28 16:57
下一篇 2016-11-28 18:01

相关推荐

  • 内核编译

    下载内核并解压:tar -xvf linux-4.14.9.tar.xz -C ./linux/     接下来是    make   config  。 (具体参照    《make   config  的几种类型》) 一般采用  #  make   menuconfig   的方式 是这个样子的: 此处有可能需要几个包,选择最简单的y…

    2018-01-01
  • MongoDB

    Edit MongoDB 手册 MongoDB 手册 第一章 Introduction MongoDB入门学习目录(建议) Databases Collections Documents 第二章 部署安装 1. Import the MongoDB public key 2. Configure the package management system (…

    Linux干货 2015-01-12
  • Linux基础指令(1)

    1.Linux上的文件管理类命令都有哪些,其常用的使用方法及相关实例演示  文件管理工具:cp mv rm cp命令 : 单源复制: cp [option]… [-T]  SOURCE DEST     -bash-4.1# …

    Linux干货 2016-11-09
  • Linux系统上命令的使用格式与十二个常用命令详解

    Linux系统上命令的使用格式 命令的语法通用格式: ~]# COMMAND OPTIONS ARGUMENTS 例如: ls -ld /var COMMAND(命令): ls ls命令用来显示目标列表 OPTIONS(选项): -ld -ld 是 -l -d 的简写 -l 以详细格式列表 -d 仅列目录 ARGUMENTS(参数): /var 命令对这个/…

    2018-02-26
  • 常用命令总结

    &:将要执行的进程送入后台进行执行alias:定义命令别名authconfig :对系统资源进行安全认证basename:抓取一个目录的基名basename pwdbzip2:压缩工具bzip2 case.sh case.sh.bz2    -[1-9]:指定压缩比   &nbsp…

    Linux干货 2017-04-09
  • Nginx负载均衡

    基于Nginx的负载均衡以及高可用简单应用 一、负载均衡配置 1、Nginx负载均衡配置 前面配置好的Nginx,可以访问之后,克隆4台,统一配置为512M,因为我的电脑内存是4G的。一台用来访问,一台用来做调度器(Director),两台web服务器(real server),Nginx前面已经介绍过了,故在此简单介绍一下那台Director的配置。 2、…

    Linux干货 2016-12-29

评论列表(1条)

  • 马哥教育
    马哥教育 2016-12-14 16:22

    grep与find是基础命令,希望你能牢记,正则表达式主要是需要多练习的,加油!