马哥教育网络班22期+第五周课程练习

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

[xw@localhost ~]$ cat /etc/passwd | grep -E "^(root|fedora|user1)\>" | cut -d: -f1,7
root:/bin/bash
fedora:/bin/bash
user1:/bin/zsh

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

[root@localhost ~]# cat /etc/rc.d/init.d/functions | grep -E -o "[^[:space:]]+\(\)"
checkpid()
__pids_var_run()
__pids_pidof()
daemon()
killproc()
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()

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

[root@localhost ~]# echo "/var/log/cron" | grep -E -o "[^/]+/?$"
cron

[root@localhost ~]# echo "/var/log/cron" | grep -E -o "^(/[^/]+)+/"
/var/log/

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])\>"
192
168
15
255
255
255
192
168
255
64
29
1
6
9
29
73
127
1
255
1
128
4
4
192
168
122
1
255
255
255
192
168
122
255

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

[root@localhost ~]# ifconfig | grep -E -o "([0-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])\.([0-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])"
192.168.0.15
255.255.255.0
192.168.0.255
127.0.0.1
255.0.0.0
192.168.122.1
255.255.255.0
192.168.122.255

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

[xw@localhost ~]$ grep -E -o "[^[:space:]]+@[^[:space:]]+(com|cn|net)" mail.txt 
ewrwer@qq.com
2335466@163.com
3434@sina.com
bjbjk454@yahoo.com.cn
jsj-df2@hotmail.com
kdiwse234@263.net

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

[root@localhost ~]# find /var/ -user root -a -group mail -ls
134321240    4 drwxrwxr-x   2 root     mail         4096 Sep 16 15:51 /var/spool/mail
134905165  104 -rw-------   1 root     mail       104325 Sep 16 15:51 /var/spool/mail/root

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

[root@localhost ~]# find / \( -nouser -o -nogroup \) -type f

[root@localhost ~]# find / \( -nouser -o -nogroup \) -atime -3

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

[root@localhost ~]# find /etc/ -perm -222 -type f

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

[root@localhost ~]# find /etc/ -size +1M -type f -exec ls -lh {} \;
-r--r--r--. 1 root root 6.7M Aug  8 16:02 /etc/udev/hwdb.bin
-rw-------. 1 root root 1.3M Aug 10 23:36 /etc/selinux/targeted/contexts/files/file_contexts.bin
-rw-r--r--. 1 root root 3.6M Aug 10 23:36 /etc/selinux/targeted/policy/policy.29
-rw-r--r--. 1 root root 1.4M Mar  6  2015 /etc/brltty/zh-tw.ctb

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

[root@localhost ~]# find /etc/init.d/ -perm -113 -type f

12、查找/usr目录下不属于root、bin或hadoop的文件;

[root@localhost ~]# find /usr/ -not \( -user root -o -user bin -o -user hadoop \)  -type f

[root@localhost ~]# find /usr \( -not -user root -a -not -user bin -a -not -user hadoop \) -type f

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

[root@localhost ~]# find /etc/ -not -perm -222 -type f

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

[root@localhost ~]# find /etc/ -mtime -7 -a -not \( -user root -o -user hadoop \) -type f

[root@localhost ~]# find /etc/ -mtime -7 -a -not -user root -a -not -user hadoop -type f

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

(0)
萝卜萝卜
上一篇 2016-10-09 09:06
下一篇 2016-10-09 09:06

相关推荐

  • SElinux

    SElinux 1.介绍: SELinux: Secure Enhanced Linux,是美国国家安全局「NSA=The National Security Agency」和SCC(Secure Computing Corporation)开发的Linux的一个强制访问控制的安全模块。2000年以GNU GPL发布,Linux内核2.6版本后集成在内核中 …

    Linux干货 2016-09-21
  • 计算机组成及各部分功能

    计算机组成及各部分功能 计算机组成 区别于利用机械原理对数据进行处理的机械计算机,计算机现在一般都指电子计算机,即电脑。计算机是一种利用电子学原理,根据一些列指令对数据进行处理的工具。 不管是机械计算机还是电子计算机其主要目的还是代替人来完成一系列的数据计算。1941年夏天诞生的阿塔纳索夫-贝瑞计算机是世界上第一部电子计算机,使用了真空管计算器,二进制数值,…

    Linux干货 2016-10-27
  • systemd管理

    centos7:systemdSystemd :系统启动和服务器守护进程管理器,负责在系统启动或运行时,          激活系统资源,服务器进程和其它进程Systemd 新特性:        系统引导时实现服务并行启动      &n…

    Linux干货 2017-04-10
  • Linux命令帮助的获取

    帮助命令 1. 使用帮助命令和帮助选项来获取帮助 2. 使用man来查看命令使用手册(manual) 3. 使用info来查看命令的信息页 4. 程序自身的帮助文档(README/INSTALL/ChangeLog) 5. 程序官方文档(官方站点:Documentation) 6. 发行版的官方文档…

    Linux干货 2016-06-01
  • Hive深入浅出

    1.  Hive是什么 1) Hive是什么? 这里引用 Hive wiki 上的介绍: Hive is a data warehouse infrastructure built on top of Hadoop. It provides tools to enable easy data ETL, a mechanism to put stru…

    Linux干货 2016-03-22
  • Linux基础之LVM

    一.LVM介绍 LVM(Logic Volume Management)逻辑卷管理器,其基本原理就是将多个磁盘的分区在逻辑上进行组合,使之成为一个大容量的磁盘进行使用,可以实现动态的分配存储空间。 LVM基本模型以及基本术语,如下图所示: PV:物理卷,从逻辑上与磁盘分区具有同样功能的设备 VG:卷组,由一个或多个物理卷组成 LV:逻辑卷,具有逻辑边界的存储…

    Linux干货 2016-11-09

评论列表(1条)

  • luoweiro
    luoweiro 2016-10-11 23:37

    对于find命令其实还有一些高级用法,比如时间轴相关的,这部分其实在日常工作中用到的也很多,可以再总结一番。