N26-第五周

1、显示当前系统上root、fedora或user1用户的默认shell;
[root@localhost ~]# grep -E ‘^(root|fedora|user1)\>’ /etc/passwd
root:x:0:0:root:/root:/bin/bash
fedora:x:4002:4002:Fedora Core:/home/fedora:/bin/tcsh
user1:x:4005:4005::/home/user1:/bin/bash

2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();
[root@localhost ~]# grep -E -o ‘^[_[:alpha:]]+()’ /etc/rc.d/init.d/functions
checkpid()
__pids_var_run()
__pids_pidof()
daemon()

3、使用echo命令输出一个绝对路径,使用grep取出其基名和路径名;
[root@localhost init.d]# echo $PWD | grep -E -o “[^/]+/?$”
init.d
[root@localhost init.d]# echo $PWD | grep -E -o ‘^/.*/’   
/etc/rc.d/

4、找出ifconfig命令结果中的1-255之间的数字;
[root@localhost ~]# ifconfig | grep -E -o ‘\<([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>’

5、写一个模式,能匹配合理的IP地址;
[root@localhost ~]# ifconfig | grep “inet\b” |cut -d’ ‘ -f10
192.168.78.17
10.1.1.2
127.0.0.1

6、写一个模式,能匹配出所有的邮件地址;
[root@localhost tmp]# grep -E ‘^[[:alnum:]]+\@[[:alnum:]]+.(com|cn)\>’ mail.test 
abc@163.com
163@163.com
sys@qq.com
root@abc163.cn

7、查找/var目录下属主的root,且属组为mail的所有文件或目录;
[root@localhost tmp]# find /var/ -user root -group mail -ls
134321240    4 drwxrwxr-x   2 root     mail         4096 3月  4 11:27 /var/spool/mail

8、查找当前系统上没有属主或属组的文件;查找当前系统上没有属主或属组,且最近三天内层被访问过的文件或目录;
[root@localhost tmp]# find / -nouser -nogroup -ls
  131    0 drwx——   2 4001     5002           59 2月 18 16:47 /home/gentoo
  132    4 -rw-r–r–   1 4001     5002           18 11月 20  2015 /home/gentoo/.bash_logout
  133    4 -rw-r–r–   1 4001     5002          193 11月 20  2015 /home/gentoo/.bash_profile
  134    4 -rw-r–r–   1 4001     5002          231 11月 20  2015 /home/gentoo/.bashrc
459464    4 -rw——-   1 4001     5002            5 2月 28 10:28 /var/tmp/gentoo/.bash_history

[root@localhost tmp]# find / -nouser -nogroup -atime -3 -ls 
  131    0 drwx——   2 4001     5002           59 2月 18 16:47 /home/gentoo
  134    4 -rw-r–r–   1 4001     5002          231 11月 20  2015 /home/gentoo/.bashrc
[root@localhost tmp]# date
2017年 03月 13日 星期一 11:05:59 CST
[root@localhost tmp]# stat /home/gentoo/.bashrc 
 文件:”/home/gentoo/.bashrc”
 大小:231             块:8          IO 块:4096   普通文件
设备:fd02h/64770d      Inode:134         硬链接:1
权限:(0644/-rw-r–r–)  Uid:( 4001/ UNKNOWN)   Gid:( 5002/ UNKNOWN)
环境:unconfined_u:object_r:user_home_t:s0
最近访问:2017-03-13 11:04:36.236017660 +0800
最近更改:2015-11-20 13:02:30.000000000 +0800
最近改动:2017-02-18 16:47:47.342556415 +0800
创建时间:-
9、查找/etc目录下所有用户都有写权限的文件;
[root@localhost tmp]# find /etc/ -perm -222 -ls
134320260    0 lrwxrwxrwx   1 root     root           17 12月 30 03:07 /etc/mtab -> /proc/self/mounts

10、查找/etc目录下大与1M,且类型为普通文件的所有文件;
[root@localhost tmp]# find /etc/ -size +1M -type f -ls
67866634 6824 -r–r–r–   1 root     root      6984832 12月 30 03:17 /etc/udev/hwdb.bin
134926960 3772 -rw-r–r–   1 root     root      3858924 11月 21  2015 /etc/selinux/targeted/policy/policy.29

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

(0)
徐 琦徐 琦
上一篇 2017-03-12
下一篇 2017-03-13

相关推荐

  • Linux的文本处理工具之sed的使用

    Sed文本处理工具 一、认识sed工具: sed是一种流编辑器,一次处理一行内容。当进行处理时,把当前处理的行存储在临时的缓冲区中(俗称“模式空间”)后,再用sed命令去处理缓冲区的内容,最后把处理过的缓冲区内容送往屏幕打印显示。接着处理下一行,不断重复进行读取、处理、输出,直到文件末尾。  注:sed命令处理文本,文件内容本身并没有改变,除非你使…

    Linux干货 2016-08-10
  • 学习开始拼搏、加油、努力

          搏一搏单车变摩托,用4个月时间为自己创造一个更好的未来,欧耶!。。。

    Linux干货 2016-10-28
  • N25第二周博客作业

    第二周博客作业: 1、linux上的文件管理命令都有哪些,其常用的使用方法及其相关示例演示。                    有  cp  mv&nbsp…

    Linux干货 2016-12-06
  • 用户组和权限管理相关作业

    1创建testuser uid 1234,主组:bin,辅助组:root,ftp,shell:/bin/csh home:/testdir/testuser     [root@ali ~]# useradd -u 1234 -g bin -G root,ftp -s /bin/csh -d /testdir/test…

    Linux干货 2016-08-02
  • 马哥教育网络第20期—IO类型与IO模型

    IO类型与IO模型 IO类型 同步与异步(synchronous,asynchronous):关注消息通知机制 同步:进程发出系统调用之后,不会立即有返回信息,但是一旦有返回信息,则一定是最终结果. 异步:进程发出系统调用之后,会有立即返回结果,但不是最终的结果,当内核处理完成之后,内核通过通知机制通知进程,该系统调用已完成. 阻塞与非阻塞(blocking…

    Linux干货 2016-06-26
  • Linux上常用文件管理命令

    1、目录管理类的命令: mkdir, rmdir,tree,cd,pwd,ls mkdir:make directories mkdir [OPTION]… DIRECTORY… -p: 自动按需创建父目录; -v: verbose,显示详细过程; -m MODE:直接给定权限; [root@centos7 ~]# mkdir -pv…

    Linux干货 2016-11-06

评论列表(1条)

  • 马哥教育
    马哥教育 2017-03-30 14:28

    正则运用的不错,正则掌握好了,今后会大大提高工作效率的。