5.程序包管理与内核命令的使用

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

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

(0)
N27_jiangyefanN27_jiangyefan
上一篇 2017-07-30 22:19
下一篇 2017-07-31 07:40

相关推荐

  • grep文本查找和正则表达式

    一、grep grep: (Global search REgular expression and Print outthe line)全局查找正则表达式并且打印结果行。不会对输入的文本进行修改。 Unix的grep家族包括grep、egrep和fgrep,egrep是grep的扩展,支持更多的正则元字符; fgrep就是fixed grep或f…

    Linux干货 2016-08-07
  • 马哥教育网络班22期中秋节课程练习1

    #!/bin/sh   set -e CheckRoot() { #check if currect use is root user     CUR_USER=`whoami`     if&nbs…

    Linux干货 2016-10-09
  • 软raid实现raid5

    现在Linux系统有磁盘情况如下 现在从sda,sdb,sdc,sdd 分区取出10G 的空间做raid5. 第一步:建立分区 现在执行fdisk  /dev/sd* 命令分区冲这四个磁盘划分10G分区 分别是sda6,sdb1,sdc1,sdd1。 具体操作如下: 分区完之后,执行#partx -a /dev/sd*  让分区生效。具体效果如下: 分区完成…

    2017-12-06
  • file 命令

    文件类型:             – 普通文件             d 目录文件   &nb…

    2017-07-23
  • 进程和进程管理工具

    进程的相关定义以及相关工具的使用

    2017-12-17
  • rsyslog+mariadb+loganalyzer实现日志采集分析

    一、总述   Linux的日志记录了用户在系统上一切操作,这些日志是使用者了解服务器的情况最好的资料。Rsyslog 是系统的一部分,能够实时的写日志,并且还可以将日志选择性的发送到远程日志服务器。   rsyslog日志服务器的优势:     1、日志统一,集中式管理     &nbsp…

    Linux干货 2017-01-10

评论列表(1条)

  • 马哥教育
    马哥教育 2017-08-04 16:17

    从作业情况来看grep和find已经基本掌握,如果加上sed和awk就理完美了,加油。