N25_第五周作业

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

[root@EASTED ~]# grep -E "(root|fedora|user1)" /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
fedora:x:1013:1013::/home/fedora:/bin/bash
user1:x:1014:1014::/home/user1:/bin/bash

[root@EASTED ~]# grep -E "(root|fedora|user1)" /etc/passwd|cut -d: -f7
/bin/bash
/sbin/nologin
/bin/bash
/bin/bash

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

[root@EASTED ~]# grep  -E  -o  "[_[:alnum:]]+\(\)"  /etc/rc.d/init.d/functions
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@aio2 ~]# echo /etc/sysconfig/network-scripts/ifcfg-eno1 | grep "[^\/]\+\/\?$"
/etc/sysconfig/network-scripts/ifcfg-eno1

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

[root@EASTED ~]# ifconfig | grep  -E  -o  "\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"
192
168
7
13
255
255
255
192
168
7
255
64
29
22
6
8
2
3
73
127
1
255
1
128
22
1
7
22
1
7
192
168
122
1
255
255
255
192
168
122
255
52
54
17
54

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

[root@aio2 ~]#  ip addr list | grep -E -o "\<((1?[0-9][0-9]?|2[0-4][0-9]|25[0-4])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-4])\>"
127.0.0.1
10.10.139.12

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

[root@aio2 ~]# grep -E "[^[:space:]].*@[^[:space:]].*" mail

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

[root@EASTED ~]# find /var -user root -a -group mail -ls 
100664302    4 drwxrwxr-x   2 root     mail         4096 1月  2 23:13 /var/spool/mail
103173137    4 -rw-------   1 root     mail          661 1月  2 12:37 /var/spool/mail/root

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

[root@EASTED ~]# find / -nouser -a -nogroup -a -atime -3
find: ‘/proc/26189’: 没有那个文件或目录
find: ‘/proc/26379’: 没有那个文件或目录
find: ‘/proc/26380/task/26380/fd/6’: 没有那个文件或目录
find: ‘/proc/26380/task/26380/fdinfo/6’: 没有那个文件或目录
find: ‘/proc/26380/fd/6’: 没有那个文件或目录
find: ‘/proc/26380/fdinfo/6’: 没有那个文件或目录
find: ‘/run/user/1000/gvfs’: 权限不够
/home/bash
/home/bash/.mozilla
/home/bash/.mozilla/extensions
/home/bash/.mozilla/plugins
/home/bash/.bash_logout
/home/bash/.bash_profile
/home/bash/.bashrc
/home/testbash
/home/testbash/.mozilla
/home/testbash/.mozilla/extensions
/home/testbash/.mozilla/plugins
/home/testbash/.bash_logout
/home/testbash/.bash_profile
/home/testbash/.bashrc
/home/basher
/home/basher/.mozilla
/home/basher/.mozilla/extensions
/home/basher/.mozilla/plugins
/home/basher/.bash_logout
/home/basher/.bash_profile
/home/basher/.bashrc
/home/nologin
/home/nologin/.mozilla
/home/nologin/.mozilla/extensions
/home/nologin/.mozilla/plugins
/home/nologin/.bash_logout
/home/nologin/.bash_profile
/home/nologin/.bashrc

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

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

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

[root@EASTED ~]# find /etc -size +1M -type f -exec ls -lh {} \;
-rw-r--r--. 1 root root 3.7M 11月 21 2015 /etc/selinux/targeted/policy/policy.29
-r--r--r--. 1 root root 6.7M 8月  31 22:36 /etc/udev/hwdb.bin
-rw-r--r--. 1 root root 1.4M 3月   6 2015 /etc/brltty/zh-tw.ctb

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

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

12、查找/usr目录下不属于root、bin或hadoop的文件;[root@EASTED ~]# find /usr -not ( -user

root -o -user bin \) -ls
68670714    4 drwx------   2 polkitd  root         4096 8月 31 22:24 /usr/share/polkit-1/rules.d
34502454   16 -rwsr-sr-x   1 abrt     abrt        15336 12月  1  2015 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

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

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

[root@EASTED ~]# find /etc -mtime -7 -a -not -user root -a -not -user hadoop -ls

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

(0)
LYFLYF
上一篇 2017-01-10 22:33
下一篇 2017-01-10 23:41

相关推荐

  • CentOS6.7上编译安装Apache2.2和Apache2.4

    centos6.7上如何编译安装Apache2.2和Apache2.4

    Linux干货 2016-05-29
  • DNS高级应用之ACL和View

    一、环境准备:     1、准备三台主机,要求如下      (1) DNS服务器双网卡:eth0:192.168.10.203  eth1: 172.16.2.10       (2)测试机1双网卡: eth0: 172.16.…

    Linux干货 2015-06-01
  • 4.Linux权限管理与grep命令应用

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。        cp -r /etc/skel /home/tuser1        chmod 700 /home/tuser1  …

    Linux干货 2017-07-23
  • 运维练习题

     1、简述TCP三次握手四次挥手过程及各过程中客户端和服务器端的状态。TCP三次握手:客户端向服务器发送SYN包,客户端进入syn_SEND状态服务端收到客户端的发送的包返回ACK+SYN包,服务器端进入SYN_RECV状态客户端收到服务器端返回的包再发ACK包,客户端进入ESTABLISHED状态,服务器收到包也进入ESTABLISHED状态客户…

    Linux干货 2016-06-12
  • Find小总结及应用

    Find总结及应用 搜索命令:     locate命令:         在文件系统上查找符合条件的文件         非实时查找( 数据库查找)…

    Linux干货 2016-08-16
  • linux发展编年史

    1965年,Bell实验室、MIT、GE(通用电气公司)准备开发Multics系统    1969年,Ken Thompson(B->C语言)利用汇编语言开发了FIle Server System(Unics,即Unix的原型)     为游戏开发出最多…

    Linux干货 2016-10-18

评论列表(1条)

  • 马哥教育
    马哥教育 2017-02-17 10:25

    写的很好,排版也很漂亮,继续加油