沉舟侧畔千帆进,枯木头前万树春

N21第五周博客作业

1、  显示/boot/grub/grub.conf中以至少一个空白字符开头的行;

~]#  grep -E "^[[:space:]]+" //boot/grub/grub.conf
root (hd0,0)
kernel /vmlinuz-2.6.32-279.el6.x86_64 ro root=/dev/mapper/vg_centos6-lv_root rd_NO_VM_LV=vg_centos6/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-279.el6.x86_64.img

2、  显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行;

~]# grep -E "^#[[:space:]]+[[:graph:]]+" /etc/rc.d/rc.sysinit
# /etc/rc.d/rc.sysinit - run once at boot time
# Taken in part from Miquel van Smoorenburg's bcheckrc.
# Check SELinux status
# Print a text banner.
# Only read this once.
# Initialize hardware
# Set default affinity
# Load other user-defined modules
# Load modules (for backward compatibility with VARs)
# Configure kernel parameters
# Set the hostname.
# Sync waiting for storage.
# Device mapper & related initialization

3、  打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行;

~]# netstat -tal | grep ".*LISTEN[[:space:]]*$"
tcp        0      0 *:55950            *:*                LISTEN     
tcp        0      0 *:sunrpc            *:*              LISTEN     
tcp        0      0 *:ssh             *:*              LISTEN     
tcp        0      0 localhost:ipp         *:*                LISTEN     
tcp        0      0 *:46286             *:*               LISTEN     
tcp        0      0 *:sunrpc            *:*              LISTEN     
tcp        0      0 *:webcache             *:*                  LISTEN     
tcp        0      0 *:ssh              *:*              LISTEN     
tcp        0      0 localhost:ipp          *:*               LISTEN     
tcp        0      0 *:43135              *:*              LISTEN

  4、  添加用户bash, testbash, basher, nologin (此一个用户的shell/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;

 ~]# grep --color=auto -o "\(^[[:alpha:]]*\):.*\1$" /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
bash:x:500:500::/home/bash:/bin/bash
nologin:x:503:503::/home/nologin:/sbin/nologin

5、  显示当前系统上rootfedorauser1用户的默认shell

~]# grep -E  "^(root|fedora|user1)" /etc/passwd
root:x:0:0:root:/root:/bin/bash

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

 ~]# egrep -o "[[:alpha:]]+\(\)" /etc/rc.d/init.d/functions
str()
checkpid()
readlink()
fgrep()
loop()
loop()
run()
pidof()
daemon()
killproc()

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

扩展:取出其路径名

~]# echo -o /etc/httpd/conf/httpd.conf | grep -o "/.*/"
/etc/httpd/conf/
 ~]# echo -o /etc/httpd/conf/httpd.conf | grep -o "[^/]*$"
httpd.conf

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

~]# ifconfig | grep -Eo "[1,2]|[1-9][0-9]|2[0-5][0-5]"
29
2
19
2
16
50
17
19
2
16
50

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

 ~]#  ifconfig |grep -o‘[1-9][0-9]\{0,3\}\.[0-9]\{0,3\}\.[0-9]\{0,3\}\.[0-9]\{1,4\}’
192.168.50.178
192.168.50.255
255.255.255.0
127.0.0.1
255.0.0.0

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

 
grep -E '[[:alnum:]]+@[[:alnum:]]+\.[[:alpha:]]\+'

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

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

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

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

 ~]# find / -nouser -o -nogroup
find: “/proc/10321/task/10321/fd/5”: 没有那个文件或目录
/andor/git-2.7.1/git.spec
/andor/git-2.7.1/configure
/andor/git-2.7.1/version
/andor/git-2.7.1/git-gui/version
/andor/android-sdk-linux
~]# find / -nouser -nogroup -atime -3
find: “/proc/10343/task/10343/fd/5”: 没有那个文件或目录
find: “/proc/10343/task/10343/fdinfo/5”: 没有那个文件或目录
/andor/android-sdk-linux
/andor/android-sdk-linux/platforms
/andor/android-sdk-linux/add-ons

 

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

~]# find /etc -perm -222
/etc/rc3.d
/etc/favicon.png
/etc/rc5.d
/etc/ssl/certs
/etc/rc0.d
/etc/rc.d/rc3.d/S28autofs

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

find /etc/ -size +1M –a –type f

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

find /etc/init.d –perm -113

15、查找/usr目录下不属于rootbinhadoop的文件;

find /usr -not \( -user root -o -user bin -o -user hadoop \)

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

find /etc ! –perm -222

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

find /etc –mtime 7 –a ! –user root –a ! –user hadoop

原创文章,作者:N21-沉舟,如若转载,请注明出处:http://www.178linux.com/26545

(0)
N21-沉舟N21-沉舟
上一篇 2016-07-29 15:23
下一篇 2016-07-29 15:23

相关推荐

  • shell脚本之 select 循环菜单及 函数

    select 循环与菜单 select variable in list    do      循环体命令   done select 循环主要用于创建菜单,按数字顺序排列的菜单项将显示在标准错误上,并显示PS3 提示符,等待用户输入 用户输入菜单列表中的某个数字,执行相应的命令…

    Linux干货 2016-08-22
  • 虚拟化介绍、以及kvm

    什么是虚拟化? 在计算机领域中虚拟化,和我们平时说的虚拟化并没有什么两样,说白了就是一个虚拟出来的东西罢了,并不是真实存在的。 虚拟化的历史 虚拟化早在20实际60年代末,由IBM开发被命名为vmm(Virtual Machine Monitor)虚拟机监视器的软件,我们知道那时候工艺技术并不发达,电脑也不像现在这样属于每家每户的标配,IBM为了解决电脑使用…

    2017-03-08
  • ip ss route nmcli netstart 命令汇总

    route命令 路由管理命令 查看:route -n [root@localhost ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.101.0 0.0.0.0 255.255.255.0 U 1 0 0 e…

    Linux干货 2017-05-07
  • 相识–Varnish

    Varnish与一般服务器软件类似,分为master(management)进程和child(worker,主要做cache的工作)进程。master进程读入命令,进行一些初始化,然后fork并监控child进程。child进程分配若干线程进行工作,主要包括一些管理线程和很多woker线程。 VCL: ”域“专有类型的配置语言 VCL有多个状态引擎,状态之间…

    Linux干货 2017-11-13
  • lvm基本应用

    前言 一种技术要知其然,还要知其所以然 lvm简介 LVM是 Logical Volume Manager(逻辑卷管理)的简写,它是Linux环境下对磁盘分区进行管理的一种机制。普通的磁盘分区管理方式在逻辑分区划分好之后就无法改变其大小,当一个逻辑分区存放不下某个文件时,这个文件因为受上层文件系统的限制,也不能跨越多个分区来存放,所以也不能同时放到别的磁盘上…

    Linux干货 2016-05-21
  • 马哥教育网络班22期+第12周作业

    week11 1、请描述一次完整的http请求处理过程; 2、httpd所支持的处理模型有哪些,他们的分别使用于哪些环境。 3、源码编译安装LAMP环境(基于wordpress程序),并写出详细的安装、配置、测试过程。 4、建立httpd服务器(基于编译的方式进行),要求:      提供两个基于名称的虚拟主…

    Linux干货 2016-10-31

评论列表(1条)

  • 马哥教育
    马哥教育 2016-07-29 16:06

    写的很好,排版也很棒,加油