N25-第五周作业

第五周

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

[root@zf ~]# grep -E "^[[:space:]]+[[:alnum:]]+" /boot/grub/grub.conf      
    root (hd0,0)     
    kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=UUID=10c8f38a-aa7e-44ba-81e2-bddbb6689b7c rd_NO_LUKS  
      KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet     
    initrd /initramfs-2.6.32-431.el6.x86_64.img

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

[root@zf ~]# grep -E "^#[[:space:]]+[^[:space:]]+" /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
    # Start any MD RAID arrays that haven't been started yet
    # Remount the root filesystem read-write.
    # Clean up SELinux labels
    # If relabeling, relabel mount points.
    # Mount all other filesystems (except for NFS and /proc, which is already
    # mounted). Contrary to standard usage,
    # filesystems are NOT unmounted in single user mode.
    # The 'no' applies to all listed filesystem types. See mount(8).
    # Update quotas if necessary
    # Check to see if a full relabel is needed
    # Initialize pseudo-random number generator
    # Configure machine if necessary.
    # Clean out /.
    # Do we need (w|u)tmpx files? We don't set them up, but the sysadmin might...
    # Clean up /var.
    # Clean up utmp/wtmp
    # Clean up various /tmp bits
    # Make ICE directory
    # Start up swapping.
    # Set up binfmt_misc
    # Boot time profiles. Yes, this should be somewhere else.
    # Now that we have all of our basic modules loaded and the kernel going,
    # let's dump the syslog ring somewhere so we can find it later
    # create the crash indicator flag to warn on crashes, offer fsck with timeout
    # Let rhgb know that we're leaving rc.sysinit

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

[root@zf ~]# netstat -tan | grep -E "LISTEN[[:space:]]*$"
    tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
    tcp        0      0 0.0.0.0:44177               0.0.0.0:*                   LISTEN      
    tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
    tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      
    tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      
    tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      
    tcp        0      0 :::111                      :::*                        LISTEN      
    tcp        0      0 :::22                       :::*                        LISTEN      
    tcp        0      0 ::1:631                     :::*                        LISTEN      
    tcp        0      0 ::1:25                      :::*                        LISTEN      
    tcp        0      0 :::55769                    :::*                        LISTEN      
    tcp        0      0 :::3306                     :::*                        LISTEN

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

[root@zf ~]# useradd bash
[root@zf ~]# useradd testbash
[root@zf ~]# useradd basher
[root@zf ~]# useradd -s /sbin/nologin nologin

[root@zf ~]# shell=$(grep "basher" /etc/passwd | cut -d: -f7)
[root@zf ~]# grep "$shell"  /etc/passwd | cut -d: -f1  
    root
    aa
    mageia
    openstack
    hadoop
    bash
    testbash
    basher

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

[root@zf ~]# grep -E "^(root|fedora)\>" /etc/passwd | cut -d: -f1,7
    root:/bin/bash
    fedora:/bin/bash

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

[root@zf ~]# grep -E "[[:alpha:]]+\>\(\)" /etc/rc.d/init.d/functions 
    fstab_decode_str() {
    checkpid() {
    __readlink() {
    __fgrep() {
    __umount_loop() {
    __umount_loopback_loop() {
    __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() {
    confirm() {
    get_numeric_dev() {
    is_ignored_file() {
    is_true() {
    is_false() {
    apply_sysctl() {
    key_is_random() {
    find_crypto_mount_point() {
    init_crypto() {

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

[root@zf ~]# echo "/usr/local/nginx/sbin/" | grep -E -o "[[:alnum:]]+/?$" | grep -o "[[:alnum:]]*" 
    sbin

[root@zf ~]# echo "/usr/local/nginx/sbin/" | grep -E -o "[/[:alnum:]]+\>" | grep -E -o "^/[/[:alnum:]]+/"
    /usr/local/nginx/

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

[root@zf ~]# ifconfig eth0 | grep -E -o "\<[1-9]\>|\<[1-9][0-9]\>|\<1[0-9][0-9]\>|\<2[0-4][0-9]\>|\<25[0-5]\>"
    29
    33
    83
    56
    10
    10
    10
    20
    10
    10
    10
    255
    255
    255
    255
    64
    1
    4
    5
    3
    9

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

[root@zf tmp]# ifconfig | grep -E -o "\<((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[1-9][0-9]?|2[0-4][0-9]|25[0-4])\>"
    10.10.10.30
    10.4.2.3
    127.0.0.1

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

[root@zf tmp]# cat mail_test 
    12457@qq.com
     w2R3@163.com
            Zhang.45e@mageedu.com
            zd_jdf@pa-jd.com
     eijm8@weij.com.cn
            fjhiu@fngy.net

[root@zf tmp]# grep -E -o "\<[^[:space:]]*\>@\<[^[:space:]]*\>\.\<[^[:space:]]*\>" mail_test 
    12457@qq.com
     w2R3@163.com
            Zhang.45e@mageedu.com
            zd_jdf@pa-jd.com
     eijm8@weij.com.cn
            fjhiu@fngy.net

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

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

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

[root@zf ~]# find / \( -nouser -o -nogroup \)
    /var/spool/mail/mandriva
    /home/mandriva
    /home/mandriva/.gnome2
    /home/mandriva/.bash_profile
    /home/mandriva/.bash_logout
    /home/mandriva/.bashrc
    /home/mandriva/.mozilla
    /home/mandriva/.mozilla/extensions
    /home/mandriva/.mozilla/plugins

[root@zf ~]# find / \( -nouser -o -nogroup \) -a -atime -3
    /var/spool/mail/mandriva
    /home/mandriva
    /home/mandriva/.gnome2
    /home/mandriva/.mozilla
    /home/mandriva/.mozilla/extensions
    /home/mandriva/.mozilla/plugins

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

[root@zf ~]# find /etc/ -perm -222
    /etc/rc1.d
    /etc/init.d
    /etc/rc0.d
    /etc/httpd/modules
    /etc/httpd/run
    /etc/httpd/logs
    ...

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

[root@zf ~]# find /etc/ -size +2M -a -type f 
    /etc/selinux/targeted/policy/policy.24
    /etc/selinux/targeted/modules/active/policy.kern

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

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

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

[root@zf ~]# find /usr/ -not \( -user root -o -user bin -o  -user hadoop \)    
    /usr/local/nginx/scgi_temp
    /usr/local/nginx/proxy_temp
    /usr/local/nginx/fastcgi_temp
    /usr/local/nginx/fastcgi_temp/1
    /usr/local/nginx/fastcgi_temp/1/00
    /usr/local/nginx/client_body_temp
    /usr/local/nginx/uwsgi_temp
    /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

[root@zf ~]# find /etc/ -not -perm  -222       
    /etc/
    /etc/rwtab
    /etc/cron.deny
    /etc/dnsmasq.d
    /etc/.pwd.lock  
    ...

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

[root@zf ~]# find /etc/ -mtime -7 -a -not \( -user root -o -user hadoop \) 
    /etc/yum.conf.bak

原创文章,作者:N25-深圳-寻觅,如若转载,请注明出处:http://www.178linux.com/64833

(0)
N25-深圳-寻觅N25-深圳-寻觅
上一篇 2016-12-26
下一篇 2016-12-26

相关推荐

  • N26-第八周

    1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。     网桥(birdge):工作于OSI模型中的数据链路层,是连接两个局域网的一种存储/转发设备,能将一个大的LAN分割为多个网段,或将两个以上的LAN互联为一个逻辑LAN,使LAN上的所有用户都可访问服务器,可以分割冲突域。   &nb…

    2017-03-08
  • Nginx的简单配置和简单实验..

    yum install nginx #安装Nginx,安装包在epel源中 systemctl start nginx.service #启动服务 #实验:配置一个虚拟主机 #先给一个网页文件 ~]#mkdir /data/nginx/vhost1 -pv ~]#vim /data/nginx/vhost1/index.html <h1>Ngin…

    Linux干货 2017-06-19
  • Linux终端类型

    Linux终端类型 关键字:linux终端,串行终端ttySn;伪终端pty;控制终端tty;控制台终端console 要想与Linux打交道,就必须学会使用Linux终端。所谓Linux终端,其实也就是一种控制台,一种字符设备,通常用tty标识,它是用户和Linux内核交互的平台,用户能在平台上通过各种指令操作Linux。终端的特殊设备文件一般分为以下几种…

    Linux干货 2016-10-19
  • 快速运用NFS共享web页面

    环境:centos7.3最小化三台,前期准备关闭防火墙和selinux 目的:通过文件共享,使客户端访问web服务器时是同样的页面。 拓扑图: 优势:减少WEB服务器的压力。 一、安装软件 NFS、WEB1、WEB2: #yum install nfs-utils -y WEB1、WEB2: #yum install httpd -y 二、配置 NFS: #…

    2017-04-27
  • 文件元数据信息详解

    文件元数据信息详解 文件的元数据是什么? 文件的数据分为两类:一类为数据,即文件的实际内容;另一类为元数据,用来描述文件的特征。 元数据内容: 文件名 文件大小 文件所在数据块 数据块的大小 文件类型 文件所在的Inode 硬链接次数 权限 属主id 属组id 最近一次访问时间戳 最近一次更改文件内容的时间戳 最近一次更改文件元数据的时间戳 查看文件的元数据…

    Linux干货 2017-07-09
  • raid5创建

    创建分区并改类型 创建raid5   创建把文件系统 生成配置文件    

    2017-12-17

评论列表(1条)

  • 马哥教育
    马哥教育 2017-02-17 11:01

    写的很好,排版也很棒,继续保持,加油。