N22—第五周作业

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

[root@localhost ~]# grep -E "^(root|fedora|user1)"  /etc/passwd |cut -d : -f 1,7

root:/bin/bash

fedora:/bin/bash

user1:/bin/bash

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

[root@localhost ~]# grep "[[:alpha:]]\+()" /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@localhost ~]# echo "/etc/rc.d/init.d" |grep -o "[^/]+$"

init.d        (取出基名)

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

/etc/rc.d/      (取出路径名)

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

[root@localhost ~]# ifconfig |grep -E "\<([1-9]|[1-9][0-9]{1,2}|2[0-4][0-9]|25[0-5])\>"

        (粗体数字为匹配结果)

        inet 192.168.1.122  netmask 255.255.255.0  broadcast 192.168.1.255

        inet6 fe80::20c:29ff:fe7f:144c  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:7f:14:4c  txqueuelen 1000  (Ethernet)

        RX packets 17093  bytes 9411784 (8.9 MiB)

        TX packets 7533  bytes 895892 (874.8 KiB)

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>

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

[root@localhost ~]# ifconfig |grep -E "\<([1-9]|[1-9][0-9]{1,2}|2[0-4][0-9]|25[0-5])\>.\<([0-9]|[1-9][0-9]{1,2}|2[0-4][0-9]|25[0-5])\>.\<([0-9]|[1-9][0-9]{1,2}|2[0-4][0-9]|25[0-5])\>.\<([0-9]|[1-9][0-9]{1,2}|2[0-4][0-9]|25[0-5])\>"

        inet 192.168.1.122  netmask 255.255.255.0  broadcast 192.168.1.255

        inet 127.0.0.1  netmask 255.0.0.0

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

[root@localhost ~]# grep -E "[^[:space:]]+@[^[:space:]]+" mail.txt

(粗体为匹配结果)

sdfkjdfoiwjflks 403562563@qq.com ldkfjlsdkfj        (地址在行中间)

liguohui2006@sina.com fldskfjlsifjlsfj        (地址在行开头)

cl,fnslkfjsifjsfk join2000@yahoo.com        (地址在行尾)

  zhangsan2001@163.com        (地址开头有空白字符)

liu_guo_hui.zhengfu@sohu.com

zhang-feng.guo@263.com

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

[root@localhost mail]# find /var -user root -group mail -ls

50331800    0 drwxrwxr-x   2 root     mail           97 Sep  8 13:17 /var/spool/mail

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

[root@localhost ~]# userdel user1        (先删除一个用户user1,用来验证效果)

[root@localhost ~]# find / -nouser -o -nogroup

/home/user1

/home/user1/.bash_logout

/home/user1/.bash_profile

/home/user1/.bashrc

/home/user1/myuser1.file

/home/user1/myuser1.txt

/home/user1/.bash_history

find: ‘/proc/3160/task/3160/fd/6’: No such file or directory

find: ‘/proc/3160/task/3160/fdinfo/6’: No such file or directory

find: ‘/proc/3160/fd/6’: No such file or directory

find: ‘/proc/3160/fdinfo/6’: No such file or directory

/var/spool/mail/user1

[root@localhost ~]# find / -nouser -o -nogroup  -atime -3      (进一步查找近3天内访问过的文件或目录)

/home/user1

/home/user1/.bash_logout

/home/user1/.bash_profile

/home/user1/.bashrc

/home/user1/myuser1.file

/home/user1/myuser1.txt

/home/user1/.bash_history

find: ‘/proc/3195/task/3195/fd/6’: No such file or directory

find: ‘/proc/3195/task/3195/fdinfo/6’: No such file or directory

find: ‘/proc/3195/fd/6’: No such file or directory

find: ‘/proc/3195/fdinfo/6’: No such file or directory

/var/spool/mail/user1

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

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

    (部分截屏)

   136    0 lrwxrwxrwx   1 root     root           17 Aug 13 07:33 /etc/mtab -> /proc/self/mounts

   153    0 lrwxrwxrwx   1 root     root           14 Aug 13 07:33 /etc/redhat-release -> centos-release

   155    0 lrwxrwxrwx   1 root     root           14 Aug 13 07:33 /etc/system-release -> centos-release

   5924    0 lrwxrwxrwx   1 root     root           22 Aug 13 07:37 /etc/grub2.cfg -> ../boot/grub2/grub.cfg

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

[root@localhost ~]# find /etc -size +1M -type f -exec ls  -lh {} \;

-r–r–r–. 1 root root 6.7M Aug 13 07:51 /etc/udev/hwdb.bin

-rw-r–r–. 1 root root 3.7M Nov 20  2015 /etc/selinux/targeted/policy/policy.29

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

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

(无输出)

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

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

50564916    0 drwx——   2 polkitd  root            6 Jun  9  2014 /usr/share/polkit-1/rules.d

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

[root@localhost ~]# find /etc/ ! -perm +222 -ls

(部分截屏)

 12066    4 -rw-r–r–   1 root     root          112 Mar  5  2015 /etc/e2fsck.conf

 12067    4 -rw-r–r–   1 root     root          936 Mar  5  2015 /etc/mke2fs.conf

  5247    4 -rw-r–r–   1 root     root           37 Aug 13 07:45 /etc/vconsole.conf

 12069    4 -rw-r–r–   1 root     root           19 Aug 13 07:45 /etc/locale.conf

 12071    4 -rw-r–r–   1 root     root           22 Aug 13 07:45 /etc/hostname

 12068    4 -rw-r–r–   1 root     root          163 Aug 13 07:33 /etc/.updated

 12074   12 -rw-r–r–   1 root     root        12288 Aug 13 07:51 /etc/aliases.db

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

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

(无输出)

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

(0)
上一篇 2016-09-11 18:59
下一篇 2016-09-11 20:11

相关推荐

  • HA Cluster 之 vrrp (keepalived)

      HA Cluster 之 vrrp (keepalived) 0x00 前言 0x01 VRRP 协议 VRRP 简介 VRRP 工作原理 VRRP负载分担方式的特点 VRRP 中的一些术语 0x02 keepalived 功用: 0x03 keepalived 配置 HA Cluster 的配置前提: 配置文件组件部分: 配置文件解析: 附:…

    Linux干货 2017-05-16
  • Linux网络相关概念及bash脚本编程练习

    马哥教育网络班第23期+第八周课堂练习 Linux网络相关概念及bash脚本编程练习 习题: 1.请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别 (1)网桥: 橋接器(英语:network bridge),又称网桥,一種網路裝置,負責網路橋接(network bridging)之用。 橋接器将网络的多个网段在数据链路层(O…

    Linux干货 2016-11-15
  • bonding

    boding制作        问题:一个网卡一个IP没有容错性     bonding是LINUX中将多网卡绑定虚拟成一块网卡,实现多网卡共同拥有一个IP,这项技术早在Sun和Cisco中被称为Trunking和Etherchannel技术。   …

    2017-03-22
  • find命令详解

    find命令详解 基本介绍 find命令用来从目录系统中查找文本不同于locate,find不从数据库中查找文件,所以find速度略逊于locate,但find是实时且准确的,而且不需要占用系统资源进行遍历文件。 其标准格式如下 find [-H] [-L] [-P] [-D debugopts] [-O level] [path…] [expressi…

    Linux干货 2017-04-09
  • linux用户管理实战

     1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登陆多次,则只显示一次即可。 [root@localhost ~]# who |cut -d ‘ ‘ -f1 |sort -u  2、取出最后登陆到当前系统的用户的相关信息。 [root@localhost ~]# who |tail -1  3、取出当前系统上被用户当做…

    2018-02-08
  • shell脚本编写-3

    1、for循环 for 变量名 in  列表;do 循环体 done 执行机制:依次将列表中元素赋值给“变量名”;每次赋值后即执一次循环体;直到列表中元素耗尽循环结束 列表生成方式: (1) 直接给出列表 (2) 整数列表: (a){start..end} (b) $(seq [start [step]] end)  (3) 返回列表的命…

    Linux干货 2016-08-18