第五周作业

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

[root@localhost ~]# awk -F: '/^(root|user1|fedora)/{print $1,"shell is",$NF}' /etc/passwd
root shell is /bin/bash
fedora shell is /bin/bash
user1 shell is /bin/bash

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

[root@localhost ~]# egrep -o '^(_|[a-z]+).*\(\)' /etc/rc.d/init.d/functions 
fstab_decode_str()
checkpid()
__readlink()
__fgrep()
__umount_loop()
__umount_loopback_loop()
__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()
confirm()
get_numeric_dev()
is_ignored_file()
is_true()
is_false()
apply_sysctl()
key_is_random()
find_crypto_mount_point()
init_crypto()

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

[root@localhost ~]# echo /etc/fstab | grep  -E  -o  "[^/]+/?$"
fstab

    扩展:取出其路径名

[root@localhost ~]# echo /etc/fstab | grep  -E  -o  "^/[^/].+/" 
/etc/

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

[root@thinkmail ~]# ifconfig | grep  -E  -o  "\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"
29
192
168
54
76
192
168
54
255
255
255
255
1
1
4
25
5
127
1
255
1

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

[root@thinkmail ~]# ifconfig eth0 |grep 'inet addr:'|egrep -o '[1][0-9]{1,2}.[0-9]{1,3}.[0-9]{1,3}.[1-9][1-5]{1,2}'
192.168.54
192.168.54.255

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

[root@thinkmail ~]# egrep --color  '[0-9A-Za-z]+@[0-9A-Za-z]+.[a-z]{1,3}' aa
hexinhai@aaa.com
adjaldal@ok.com
jdlalaf@baidu.cn
jdlalaf@baidu.cc
jdlalaf@baidu.net

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

[root@thinkmail ~]# find /var/ -user root -group mail
/var/spool/mail

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

[root@localhost tmp]# find /tmp -nouser -o -nogroup |xargs ls -l
-rw-r--r-- 1  503 503 0 9月  13 16:50 /tmp/aa
-rw-r--r-- 1 root 503 0 9月  13 16:51 /tmp/bb

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

find /tmp -nouser -o -nogroup -atime -3 |xargs ls -l

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

[root@thinkmail tmp]# find /etc/ -type f -perm -222 -ls
131264    0 -rw-rw-rw-   1 root     root            0 9月 13 16:55 /etc

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

[root@thinkmail tmp]# find /etc/ -size +1M |xargs ls -lh
-rw-r--r--. 1 root root 6.9M 9月   9 13:54 /etc/selinux/targeted/modules/active/policy.kern
-rw-r--r--. 1 root root 6.9M 9月   9 13:54 /etc/selinux/targeted/policy/policy.24

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

[root@thinkmail tmp]# find /etc/init.d/ -perm -111 |xargs  ls -l
-rwxr-xr-x  1 root root     0 9月  13 17:01 /etc/init.d/aaa.sh
-rwxr-xr-x  1 root root  1288 5月  12 04:43 /etc/init.d/abrt-ccpp
-rwxr-xr-x  1 root root  1628 5月  12 04:43 /etc/init.d/abrtd
-rwxr-xr-x  1 root root  1642 5月  12 04:43 /etc/init.d/abrt-oops
-rwxr-xr-x  1 root root  1818 2月  17 2016 /etc/init.d/acpid
-rwxr-xr-x  1 root root  2062 2月  20 2015 /etc/init.d/atd
-rwxr-xr-x  1 root root  3580 5月  11 14:17 /etc/init.d/auditd
-rwxr-xr-x. 1 root root  4043 2月  22 2013 /etc/init.d/autofs
-r-xr-xr-x  1 root root  1343 8月  24 02:37 /etc/init.d/blk-availability
-rwxr-xr-x  1 root root  5221 7月  13 00:27 /etc/init.d/cgconfig
-rwxr-xr-x  1 root root  3580 7月  13 00:27 /etc/init.d/cgred
-rwxr-xr-x  1 root root 11864 7月  24 2015 /etc/init.d/cpuspeed
-rwxr-xr-x. 1 root root  2793 7月  19 2011 /etc/init.d/crond
-rwxr-xr-x  1 root root  1801 10月 15 2014 /etc/init.d/haldaemon
-rwxr-xr-x. 1 root root  5829 1月   9 2013 /etc/init.d/halt
-rwxr-xr-x. 1 root root  9515 2月  22 2013 /etc/init.d/ip6tables

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

[root@thinkmail init.d]# find /usr/ -not \( -user root -o -user bin -o -user hadoop \)
/usr/xiaoxin
/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

[root@thinkmail init.d]# find /etc/ -perm -444

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

find /etc -mtime -7 -a -not \( -user root -o -user hadoop \) -ls

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

(0)
上一篇 2016-09-15 22:20
下一篇 2016-09-15 22:21

相关推荐

  • 关于文件查找和解压缩

                     文件查找和解压缩在文件系统上查找符合条件的文件,文件查找的工具有两个,locate 和find文件查找分为:          &nbs…

    系统运维 2016-08-18
  • Centos6.5基于SSL密码认证部署ELK(Elasticsearch+Logstash+kibana)

    1       简介 本章我们来介绍Centos6.5基于SSL密码认证部署ELK(Elasticsearch 1.4.4+Logstash 1.4.2+kibana3),同时为大家介绍如何集合如上组件来收集日志,本章的日志收集主要为大家介绍SYSTEM日志收集. 集中化日志收集主要应用场景是在同一…

    Linux干货 2015-06-18
  • N25-第一周作业

    第一周博客作业 1.描述计算机的组成及其功能 2.按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别 3.描述Linux哲学思想,并按照自己的理解对其进行解释性描述。 4.说明Linux系统上命令的使用格式:详细介绍,ifconfg,echo,tty,startx,export pwd,history,shutdown,poweroff,rebo…

    Linux干货 2016-12-02
  • 学习宣言

    我是喻成,我参加了马帮第22期的linux运维网络班,于2016年8月开始跟随马哥学习linux, 我的学习宣言是:要享受学习的每一刻,我思故我在。

    Linux干货 2016-08-15
  • LVM逻辑卷管理

    一、简述 什么是逻辑卷?LVM(Logical Volume Manager)利用Linux内核device-mapper实现存储系统的虚拟化。通过LVM,把底层存储硬件抽象化成存储逻辑块,再将这些逻辑块集合构成存储池,从存储池空间划分分区,可以简单地扩大或缩小分区,而不用担心硬盘没有足够的连续空间。 使用逻辑卷分区有什么用?使用逻辑卷分区重点在于可以弹性地…

    Linux干货 2016-09-06
  • Linux文件与目录管理之权限与命令之间的关系

    Linux文件与目录管理之权限与命令之间的关系 我们知道权限对于用户账户来说是非常重要的,因为它可以限制用户能不能读取/新建/删除/修改文件或目录。在这我们就来说明下什么命令在什么样的权限下才能够运行。         让用户能进入某目录成为“可工作目录”的基本权限是什么     &nbs…

    Linux干货 2017-04-24

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-19 18:29

    匹配ip地址不对,在好好想想