N22+张zhangzhang+第5周练习作业

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

[root@zxn ~]# cat /etc/passwd | grep -E "^root\>" | cut -d: -f7
/bin/bash

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

cat /etc/rc.d/init.d/functions | grep -E "\<[[:alpha:]]+\>\(\)"
checkpid() {daemon() {killproc() {pidfileofproc() {pidofproc() {status() {success() {failure() {passed() {warning() {action() {strstr() {

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

取基名

[root@zxn ~]# echo /etc/rc.d/init.d/functions | grep -E -o  "[^/]+/?$"
functions

取路径名:

[root@zxn ~]# echo /etc/rc.d/init.d/functions | grep -E -o  "^/.*/"
/etc/rc.d/init.d/

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

[root@zxn ~]# ifconfig | grep  -E  --color  "\<([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\>"
        inet 192.168.1.15  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fec1:ddb3  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:c1:dd:b3  txqueuelen 1000  (Ethernet)
        RX packets 30268  bytes 4171288 (3.9 MiB)
        TX packets 4401  bytes 1321341 (1.2 MiB)
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        RX packets 41  bytes 3960 (3.8 KiB)
        TX packets 41  bytes 3960 (3.8 KiB)

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

[root@zxn ~]#  ifconfig |grep -E --color "[1-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[1-9]{0,1}[0-9]{1,3}"
        inet 192.168.1.15  netmask 255.255.255.0  broadcast 192.168.1.255
        inet 127.0.0.1  netmask 255.0.0.0

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

[root@zxn ~]# echo "zxn@ncist.edu.cn" | grep -E -o ".*@[[:alnum:]]+.(com|cn|edu.cn)$"
zxn@ncist.edu.cn

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

[root@zxn ~]# find /var/* -user root -group mail
/var/spool/mail
/var/spool/mail/root
[root@zxn ~]# ls -ld /var/spool/mail/root
-rw-------. 1 root mail 623 9月  10 18:40 /var/spool/mail/root

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

[root@zxn ~]# find  /  \( -nogroup -o -nouser \) -ls
102325563    0 -rw-rw----   1 1002     mail            0 8月 23 23:46 /var/spool/mail/user2102325565    0 -rw-rw----   1 1003     mail            0 8月 23 23:46 /var/spool/mail/user33050125    4 drwx------   5 hadoop   1001         4096 8月 24 00:54 /home/user139252847    0 drwxr-xr-x   4 hadoop   1001           37 8月 14 09:19 /home/user1/.mozilla
[root@zxn ~]# find / \( -nogroup -o -nouser \) -atime -3

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

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

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

[root@zxn ~]# find /etc -size +1M -type f -ls
2287674 6228 -r--r--r--   1 root     root      6376691 8月 14 09:26 /etc/udev/hwdb.bin
102088141 3752 -rw-r--r--   1 root     root      3839718 3月  6  2015 /etc/selinux/targeted/policy/policy.29
101494228 1336 -rw-r--r--   1 root     root      1367395 3月  6  2015 /etc/brltty/zh-tw.ctb

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

[root@zxn ~]# find /etc/init.d -perm -113 -ls
33701805    0 lrwxrwxrwx   1 root     root   11 8月 14 09:20 /etc/init.d -> rc.d/init.d

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

[root@zxn ~]# find /usr -not \( -user root -o -user bin -o -user hadoop \) -ls
921800    4 drwx------   2 polkitd  root  4096 8月 14 09:27 /usr/share/polkit-1/rules.d
34446281   12 -rwsr-sr-x   1 abrt  abrt   11232 3月 24  2015 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

[root@zxn ~]# find /etc/ -not -perm -222 -type f -ls
/smartd_warning.sh
36069630    4 -rw-r--r--   1 root     root            1 10月  7  2014 /etc/at.deny
35959044    4 -rw-r--r--   1 root     root         2872 6月 10  2014 /etc/pinforc
35958973    4 -rw-r-----   1 root     root         3181 3月  6  2015 /etc/sudo-ldap.conf

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

[root@zxn ~]# find /etc -mtime -7 -not \( -user root -o -user hadoop \)

原创文章,作者:N22-北京-张zhangzhang,如若转载,请注明出处:http://www.178linux.com/45106

(0)
N22-北京-张zhangzhangN22-北京-张zhangzhang
上一篇 2016-09-15 22:21
下一篇 2016-09-15 22:21

相关推荐

  • btrfs文件系统常用命令使用

    Btrfs,也可称为B-tree,Butter FS,Better FS,是CentOS7中一种新型的文件系统。 核心特性: 1.多物理卷支持,可由多个物理卷(pv)组成,支持raid,以联机添加删除 2.支持写实复制(Copy on Write,Cow) 复制一份修改,改好之后用指针替换,出错时指回原本文件。而不是就地修改 3.数据及元数据校验码:chec…

    Linux干货 2016-03-07
  • ACL权限管理练习

    ACL简介;
    权限管理练习

    2017-09-11
  • Bash的基础特性(二)

    Bash的基础特性(二) glob文件通配符 (* ; ? ; [ ] ; [^ ] ) 星号* 匹配任意所有字符的 [root@lyp ~]# ls h* hello.sh hello.shbak ?匹配单个字符 ls ???? 查看四个字符命名的文件 [0-9]匹配数字 [a-z] 字母 字母的顺序安装 a A b B c C… z Z 匹配的a-z […

    Linux干货 2017-04-01
  • 软链接和硬链接详解

    软连接和硬链接图解 硬链接 符号链接 软链接和硬链接详解 软链接和硬链接详解 Linux下的链接文件有点类似于Windows的快捷方式,但又不完全一样。链接文件有两种:一种是硬链接,另一种是符号链接(又称软链接)。 UNIX文件系统提供了一种将不同文件链接至同一个文件的机制,我们称这种机制为链接。它可以使得单个程序对同一文件使用不同的名字。这样的好处是文件系…

    Linux干货 2016-09-06
  • DNS中view的实现

    [root@localhost /var/named]# ll total 32 -rw-r–r–. 1 root  root   173 Jan 20 14:46 magedu.com.zone -rw-r–r–. 1 root  root   173 Jan 20 14:46 magedu.com.zone…

    2018-01-22
  • 初识Linux

    本文对计算机组成及其功能、Linux的发行版、以及Linux的哲学思想进行了简单的介绍;同时对Linux系统中常用的基础命令以及如何获取帮助信息进行了详细的说明。

    2018-01-14