grep、egrep、vim练习

1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及内部文件的属组和其它用户均没有任何访问权限。

        [root@localhost ~]# install -d -m 600 /etc/skel /home/tuser1
        [root@localhost ~]# ls -l /home
        drw-------.  2 root        root           6 11月 15 20:23 tuser1

2、编辑/etc/group文件,添加组hadoop。

        [root@localhost ~]# vim /etc/group
        [root@localhost ~]# cat /etc/group
        hadoop:x:1002:

3、手动编辑/etc/passwd文件新增一行,添加用户hadoop,其基本组id为hadoop组的id号;其家目录为/home/hadoop.

        [root@localhost ~]# vim /etc/passwd
        [root@localhost ~]# idhadoop
        uid=1002(hadoop) gid=1002(hadoop) 组=1002(hadoop)  
        [root@localhost ~]# cat /etc/passwd
        hadoop:x:1002:1002::/home/hadoop:/bin/bash

4、复制/etc/skel目录为/home/hadoop/,要求修改hadoop目录的属组和其它用户没有任何访问权限。

        [root@localhost ~]# install -d -m 600 /etc/skel/ /home/hadoop
        [root@localhost ~]# ls -l /home
        drw-------.  2 root        root           6 11月 15 20:49 hadoop

5、修改/home/hadoop目录及其内部所以文件的属主为hadoop,属组为hadoop。

        [root@localhost ~]# install -d -o hadoop -g hadoop /home/hadoop/ /home/hadoop/
        [root@localhost ~]# ls -l /home/
        drwxr-xr-x.  2 hadoophadoop         6 11月 15 20:49 hadoop

6、显示/proc/meminfo文件中以大写或小写s开头的行,两种方式。

        [root@localhost ~]# grep  "^[sS]" /proc/meminfo
        SwapCached:            0 kB
        SwapTotal:       2098172 kB
        SwapFree:        2098172 kB
        Shmem:              7196 kB
        Slab:              93980 kB
        SReclaimable:      47692 kB
        SUnreclaim:        46288 kB
        [root@localhost ~]# grep -i  "^s" /proc/meminfo
        SwapCached:            0 kB
        SwapTotal:       2098172 kB
        SwapFree:        2098172 kB
        Shmem:              7196 kB
        Slab:              93980 kB
        SReclaimable:      47692 kB
        SUnreclaim:        46288 kB

7、显示/etc/passwd文件中默认shell为非/sbin/nologin的用户。

        [root@localhost ~]# grep  -o ".*[^/sbin/nologin]" /etc/passwd
        root:x:0:0:root:/root:/bin/bash
        bin:x:1:1:bin:/bin:
        daemon:x:2:2:daemon:/sbin:
        adm:x:3:4:adm:/var/adm:
        lp:x:4:7:lp:/var/spool/lpd:
        sync:x:5:0:sync:/sbin:/bin/sync
        shutdown:x:6:0:shutdown:/sbin:/sbin/shutdow
        halt:x:7:0:halt:/sbin:/sbin/halt
        mail:x:8:12:mail:/var/spool/mail:
        operator:x:11:0:operator:/root:
        games:x:12:100:games:/usr/games:
        ftp:x:14:50:FTP User:/var/ftp:
        nobody:x:99:99:Nobody:/:
        avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:
        systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:
        systemd-network:x:998:996:systemd Network Management:/:
        dbus:x:81:81:System message bus:/:
        polkitd:x:997:995:User for polkitd:/:
        abrt:x:173:173::/etc/abrt:
        colord:x:996:994:User for colord:/var/lib/colord:
        libstoragemgmt:x:995:992:daemon account for libstoragemgmt:/var/run/lsm:
        setroubleshoot:x:994:991::/var/lib/setroubleshoot:
        rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:
        rtkit:x:172:172:RealtimeKit:/proc:
        chrony:x:993:990::/var/lib/chrony:
        tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:
        geoclue:x:992:989:User for geoclue:/var/lib/geoclue:
        usbmuxd:x:113:113:usbmuxd user:/:
        ntp:x:38:38::/etc/ntp:
        mysql:x:27:27:MariaDB Server:/var/lib/mysql:
        rpcuser:x:29:29:RPC Service User:/var/lib/nfs:
        nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:
        sssd:x:991:988:User for sssd:/:
        pulse:x:171:171:PulseAudio System Daemon:/var/run/pulse:
        gdm:x:42:42::/var/lib/gdm:
        postfix:x:89:89::/var/spool/postfix:
        sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:
        tcpdump:x:72:72::/:
        dunwen_jian:x:1000:1000::/home/dunwen_jian:/bin/bash
        centos01:x:1001:1001::/home/centos01:/bin/bash
        hadoop:x:1002:1002::/home/hadoop:/bin/bash

8、显示/etc/passwd文件中默认shell为/bin/bash的用户。

        [root@localhost ~]# grep ".*/bin/bash" /etc/passwd
        root:x:0:0:root:/root:/bin/bash
        dunwen_jian:x:1000:1000::/home/dunwen_jian:/bin/bash
        centos01:x:1001:1001::/home/centos01:/bin/bash
        hadoop:x:1002:1002::/home/hadoop:/bin/bash

9、找出/etc/passwd文件中的一位数或两位数。

        [root@localhost ~]# grep "\<[0-9]\{1,2\}\>" /etc/passwd
        root:x:0:0:root:/root:/bin/bash
        bin:x:1:1:bin:/bin:/sbin/nologin
        daemon:x:2:2:daemon:/sbin:/sbin/nologin
        adm:x:3:4:adm:/var/adm:/sbin/nologin
        lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
        sync:x:5:0:sync:/sbin:/bin/sync
        shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
        halt:x:7:0:halt:/sbin:/sbin/halt
        mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
        operator:x:11:0:operator:/root:/sbin/nologin
        games:x:12:100:games:/usr/games:/sbin/nologin
        ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
        nobody:x:99:99:Nobody:/:/sbin/nologin
        dbus:x:81:81:System message bus:/:/sbin/nologin
        rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
        tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
        ntp:x:38:38::/etc/ntp:/sbin/nologin
        mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
        rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
        gdm:x:42:42::/var/lib/gdm:/sbin/nologin
        postfix:x:89:89::/var/spool/postfix:/sbin/nologin
        sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
        tcpdump:x:72:72::/:/sbin/nologin

10、显示/boot/grub2/grub.cfg文件中至少一个空白字符开头的行。

[root@localhost ~]# grep "^[[:space:]]\+[[:space:]]" /boot/grub2/grub.cfg
  load_env
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
   set default="${saved_entry}"
  menuentry_id_option="--id"
  menuentry_id_option=""
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
  set timeout_style=menu
  set timeout=5
  set timeout=5
  source ${prefix}/user.cfg
  if [ -n ${GRUB2_PASSWORD} ]; then
    set superusers="root"
    export superusers
    password_pbkdf2 root ${GRUB2_PASSWORD}
  fi
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  0e66967e-71ab-473f-a181-635ec181283c
      search --no-floppy --fs-uuid --set=root 0e66967e-71ab-473f-a181-635ec181283c
      search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  0e66967e-71ab-473f-a181-635ec181283c
      search --no-floppy --fs-uuid --set=root 0e66967e-71ab-473f-a181-635ec181283c
  source ${config_directory}/custom.cfg
  source $prefix/custom.cfg;

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

        [root@localhost ~]# grep "^#[[:space:]]\+[^[:space:]]" /etc/rc.d/rc.local
        # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
        # It is highly advisable to create own systemd services or udev rules
        # to run scripts during boot instead of using this file.
        # In contrast to previous versions due to parallel execution during boot
        # this script will NOT be run after all other services.
        # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
        # that this script will be executed during boot.

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

    [root@localhost ~]# netstat -tan | grep "\<LISTEN[[:space:]]\+"
    tcp        0      0 0.0.0.0:53164             0.0.0.0:*           LISTEN      
    tcp        0      0 0.0.0.0:111               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 127.0.0.1:25              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 :::34985                  :::*                LISTEN

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

        [root@localhost ~]# grep -E "^([^:]+\>).*\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:4004:4004::/home/bash:/bin/bash
        nologin:x:4007:4007::/home/nologin:/sbin/nologin

 

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

(0)
上一篇 2016-11-17 21:29
下一篇 2016-11-18 15:35

相关推荐

  • Linux 目录结构

    Linux 目录结构 1.     前言     Linux 是一种开源的,且非常流行的操作系统,发行版本众多。为了统一和规范linux系统的主要目录名及其用途,提出了FHS标准,FHS是File Hierarchy Standard的简写。Linu…

    Linux干货 2015-07-26
  • 【招聘福利】上海/北京/深圳丨 云络科技丨招募linux系统运维工程师

    岗位要求: 1,安装服务器 – Linux CentOS + netinstall 2.服务器安全 – 用户、权限、iptables、sudo 3.计划部署Linux?高可用性,包括HA,LB 4.协助Leader完成复杂的网络设计 (完全冗余/故障迁移/高可用性) 5.用linux命令查看服务器(top/iostat/vmstat/sar/等) 6.安装、…

    Linux干货 2016-04-05
  • hello 北京&Linux启程

    北京初感&Linux启程

    Linux干货 2018-03-26
  • Awk 高级应用

                              Awk 简介   Awk 是一种变成语言,用于在Linux/UNIX下对文本和数据进行扫描与处理,数据可以来自标准输入,文件 ,管道。Awk分别代表其作者的姓…

    2017-07-17
  • 使用ssh比较慢的小结

    1)情况说明 a、ping ip,响应正常 b、telnet ip,响应正常 c、ssh ip,响应慢,但是等很大会后还是能打开 2)处理方法 方法1: 修改本地中的/etc/ssh/ssh_config,把参数改为GSSAPIAuthentication no 方法2: a、修改远程服务器端的/etc/ssh/sshd_config ,把参数改为GSSAP…

    系统运维 2016-12-05
  • Linux磁盘及文件系统

    Linux磁盘及文件系统 一、硬盘 硬盘接口 PATA(Paralled Advanced Technology Attachment,并行的先进技术规范),也叫IDE(Integrated Drive Eelectronics,集成电路驱动设备),是作为一种简单而廉价的接口而开发的。速度中等,容量大而且非常便宜。 串行ATA接口SATA(Serial AT…

    Linux干货 2016-09-19