grep 正则表达式 find

1.显示当前系统上root,fedora 或user1用户的默认shell
[root@centos7 ~]# grep -E  “^(root|fedora|user1)” /etc/passwd
root:x:0:0:root:/root:/bin/bash
fedora:x:2003:2003::/home/fedora:/bin/bash
user1:x:2004:2004::/home/user1:/bin/bash
2.找出 /etc/rc.d/init.d/functions文件中某个单词后面跟一组小括号的行,形如:hello();
[root@centos7 ~]# cat /etc/rc.d/init.d/functions |grep -E “[[:alpha:]]{1,}\(\) “
checkpid() {
__kill_pids_term_kill_checkpids() {
__kill_pids_term_kill() {
__pids_var_run() {
__pids_pidof() {
daemon() {
killproc() {
pidfileofproc() {
3.使用echo命令输出一个绝对路径,使用grep取出莫个基名。
[root@centos7 fedora]# echo /home/fedora/|grep -E “[[:alpha:]]{1,}/$”
/home/fedora/
4.找出ifconfig命令结果中的1-255之间的数字。
[root@centos7 ~]# ifconfig|grep -E -o  “\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[1-5])\>”
5挑战题:写一个模式,能匹配合理的ip地址;
[root@centos7 ~]# ifconfig|grep -E -o  “\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[1-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[1-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[1-5])\>\.\<([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[1-5])\>”
192.168.119.137
255.255.255.0
192.168.119.255
127.0.0.1
255.0.0.0
192.168.122.1
255.255.255.0
192.168.122.255
6.挑战题:写一个模式,能匹配出所有的邮件地址;
[root@centos7 ~]# cat email |grep -E “^([0-9]|[a-zA-Z])([[:alnum:]]|[[:punct:]])+@[[:alnum:]]*\.(com|cn)$”
7.查找/var目录下属主为root,且属组为mail的所有文件或目录;
[root@centos7 var]# find /var/ -user root -a -group mail -ls
33701767    0 drwxrwxr-x   2 root     mail          105 Sep 17 07:19 /var/spool/mail
8.查找当前系统上没有属主或属组的文件;
进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的目录或文件;
[root@centos7 var]# find / \( -nouser -o -nogroup \) -atime +3 -ls
find: ‘/proc/7176/task/7176/fd/6’: No such file or directory
find: ‘/proc/7176/task/7176/fdinfo/6’: No such file or directory
find: ‘/proc/7176/fd/6’: No such file or directory
find: ‘/proc/7176/fdinfo/6’: No such file or directory
34754918    0 -rw-rw—-   1 1005     mail            0 Sep  2 11:28 /var/spool/mail/mandriva
18360951    4 -rw-r–r–   1 1005     distro         18 Aug  2  2016 /home/mandriva/.bash_logout
18360952    4 -rw-r–r–   1 1005     distro        193 Aug  2  2016 /home/mandriva/.bash_profile
18360953    4 -rw-r–r–   1 1005     distro        231 Aug  2  2016 /home/mandriva/.bashrc
34754923    4 -rw——-   1 1005     distro         11 Sep  2 11:30 /home/mandriva/.cache/abrt/lastnotification
18360956    4 -rw——-   1 1005     distro         24 Sep  2 12:13 /home/mandriva/.bash_history
9.查找/etc目录下所有用户都有写权限的文件;
[root@centos7 etc]# find /etc/ -perm /222 -type f -ls
10. 查找/etc目录下大于1M,且类型为普通文件的所有文件;
find /etc/ -size 1M  -type f -ls
 

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/87385

(0)
469008940469008940
上一篇 2017-09-18 16:09
下一篇 2017-09-18 19:58

相关推荐

  • DNS服务器搭建

    1. 配置正向解析 1.安装bind yum install bind bind-utils -y 2.配置/etc/named.conf,需要修改的地方 listen-on port 53 { 127.0.0.1; 192.168.42.135; }; allow-query { any; }; dnssec-enable no; dnssec-valid…

    Linux干货 2017-05-24
  • Linux启动和内核管理

                                        Linux启动和内核管理 本章内容: centos5和centos6的启动流程 服务管理 grub…

    系统运维 2016-09-21
  • 第三周博客作业

    who useradd usermod groupadd

    Linux干货 2017-12-17
  • Linux系统中文件权限(特殊权限)的相关认识

    文件属性 在linux系统中一切皆文件,所有的数据都是以文件的形式存储在系统中,我们可以通过ls命令可以查看文件的相关属性,如下图:                                &n…

    Linux干货 2016-08-04
  • N25-第二周作业

    ①Linux文件管理命令常用方法 Linux常见文件类型 -:files,常规文件 d: directory,目录文件 b: block device,块设备文件 c:character device,字符设备文件 l:symbolic link,符号链接文件 p: pipe,命名管道 s: socket,套接字文件 命令管理工具指南:cp、rm、mv 1.…

    Linux干货 2016-12-13
  • Shell脚本编程基础之一

      Linux为高效管理系统,提供了CLI命令行接口,供用户在命令提示符下输入命令,它有很多bash shell基础特,根据这些特性能够很灵活的使用命令,也支持使同时输入多个命令执行,命令之间用冒号分隔;但是要完成复杂多次重复性的操作,非常不便,系统管理工作变得很是繁忙,很难轻松完成工作任务;不过Linux的shell支持脚本编程,通过编写纯文本格…

    Linux干货 2016-08-15