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.www58058.com/59578

(0)
641348038@qq.com641348038@qq.com
上一篇 2016-11-17 21:29
下一篇 2016-11-18 15:35

相關推薦

  • heartbeartv2實現lamp高可用-week17

    3、基于heartbeat v2 crm實現HA LAMP組合;要求,部署wordpress,用于編輯的文章中的任何數據在節點切換后都能正常訪問; 拓撲: 環境: CentOS6.6NFS: 172.16.0.34 輸出mysql數據目錄ntp: 172.16.0.31 時間服務器node1: 172.16.0.32 heartbeart+httpd+php…

    Linux干貨 2017-05-23
  • shell腳本之選擇與執行

    流程控制 ? 過程式編程語言: 順序執行 選擇執行 循環執行 選擇執行:if語句 ? 注意:if語句可嵌套 ? 單分支 if 判斷條件:then 條件為真的分支代碼 fi ? 雙分支 if 判斷條件; then 條件為真的分支代碼 else 條件為假的分支代碼 fi 多分支 if…

    Linux干貨 2016-09-19
  • 馬哥教育網絡20期+第二周練習博客

    1、Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。 2、bash的工作特性之命令執行狀態返回值和命令行展開所涉及的內容及其示例演示。 3、請使用命令行展開功能來完成以下練習:    (1)、創建/tmp目錄下的:a_c, a_d, b_c, b_d   …

    Linux干貨 2016-06-20
  • 第四周博客分享

                    時間匆匆,轉眼來馬哥已經快一個月了,這一個月對我來說是收獲滿滿,每天都在學到新的東西。       &nbs…

    2017-08-06
  • 搜索引擎的檢索模型-查詢與文檔的相關度計算

    1. 檢索模型概述       搜索結果排序時搜索引擎最核心的部分,很大程度度上決定了搜索引擎的質量好壞及用戶滿意度。實際搜索結果排序的因子有很多,但最主要的兩個因素是用戶查詢和網頁內容的相關度,以及網頁鏈接情況。這里我們主要總結網頁內容和用戶查詢相關的內容。     &nbsp…

    2015-12-10
  • liunx初探

    計算機的五大單元: 輸出單元、輸入單元、cpu內部控制單元、算術邏輯單元和內存。 計算機三大組成部分: 輸入單元:鍵盤、鼠標等等 輸出單元:屏幕、打印機等 中央處理器(CPU):含有算術邏輯、控制、記憶等 CPU種類有兩種分別是:   精簡指令集(RISC):這種cpu微指令比較精簡,每個指令的執行時間都很短,完成的操作也很簡單。常見的簡單指令集C…

    Linux干貨 2016-09-14
欧美性久久久久