第四周作業

1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。

                使用到命令chmod

                    chmod 修改文件或目錄權限

                        chmod [option] MODE    file

                                option

                                    -R 遞歸修改

[root@localhost ~]# cp -r /etc/skel /home/tuser1
[root@localhost ~]# ll /home/tuser1 -d
drwxr-xr-x 2 root root 59 Feb  2 12:30 /home/tuser1
[root@localhost ~]# chmod 700 /home/tuser1
[root@localhost ~]# ll /home/tuser1/ -d
drwx------ 2 root root 59 Feb  2 12:30 /home/tuser1/

2、編輯/etc/group文件,添加組hadoop。

[root@localhost ~]# echo "hadoop:x:3007:" >>/etc/group
[root@localhost ~]# tail -1 /etc/group

3、手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號;其家目錄為/home/hadoop。

[root@localhost ~]# echo  "hadoop:x:3007::3007::/home/hadoop:/bin/bash" >> /etc/passwd

4、復制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其它用戶沒有任何訪問權限。

[root@localhost ~]# cp  -a /etc/skel/ /home/hadoop
[root@localhost ~]# chmod 700 /home/hadoop
[root@localhost ~]# ll -d /home/hadoop/
drwx------. 2 root root 59 Oct 27 18:20 /home/hadoop/

5、修改/home/hadoop目錄及其內部所有文件的屬主為hadoop,屬組為hadoop。

[root@localhost ~]# chown -R hadoop:hadoop /home/hadoop
[root@localhost ~]# ll -d /home/hadoop/
drwx------. 2 hadoop hadoop 59 Oct 27 18:20 /home/hadoop/

6、顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用兩種方式;

        使用到命令grep 文本過濾工具

                    grep [option] PATTERN file   

                        option

                                  -i  忽略大小寫

                                 -o 只顯示匹配到的文本

                                 -v 只顯示不匹配的文本

                                 -E 支持擴展正則表達式

                                 -q 不輸出任何內容

                                 -A #  后#行

                                 -B  # 前#行

                                 -C # 前后各#行

                        PATTERN支持使用正則表達式和擴展的正則表達式

方法1

[root@localhost ~]# grep -i ^s /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:              4676 kB
Slab:              51208 kB
SReclaimable:      26556 kB
SUnreclaim:        24652 kB

方法2

[root@localhost ~]# grep ^[s,S] /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:              4676 kB
Slab:              51208 kB
SReclaimable:      26556 kB
SUnreclaim:        24652 kB

  方法3

[root@localhost ~]# grep -E "^(s|S)" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:              4676 kB
Slab:              51208 kB
SReclaimable:      26556 kB
SUnreclaim:        24652 kB

  

7、顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶;

[root@localhost ~]# grep -v "/sbin/nologin" /etc/passwd| cut -d: -f 1
root
sync
shutdown
halt
mageia
slackware
clouds
openstack
hadoop

8、顯示/etc/passwd文件中其默認shell為/bin/bash的用戶;

[root@localhost ~]# grep "/bin/bash" /etc/passwd| cut -d: -f 1
root
mageia
clouds
openstack
hadoop

9、找出/etc/passwd文件中的一位數或兩位數;

[root@localhost ~]# grep -E "\<[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
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

10、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行;

[root@localhost ~]# grep -E ^" " /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
  source ${config_directory}/custom.cfg
  source $prefix/custom.cfg;
[root@localhost ~]# grep  ^" " /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
  source ${config_directory}/custom.cfg
  source $prefix/custom.cfg;

11、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行;

[root@localhost ~]# grep -E "^#[[: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"' '*$
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN

13、添加用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息;

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

14、顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用三種方式;

方法1
[root@localhost ~]# grep -i ^s /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:              4676 kB
Slab:              51208 kB
SReclaimable:      26556 kB
SUnreclaim:        24652 kB
方法2
[root@localhost ~]# grep ^[s,S] /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:              4676 kB
Slab:              51208 kB
SReclaimable:      26556 kB
SUnreclaim:        24652 kB
  方法3
[root@localhost ~]# grep -E "^(s|S)" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       1048572 kB
SwapFree:        1048572 kB
Shmem:              4676 kB
Slab:              51208 kB
SReclaimable:      26556 kB
SUnreclaim:        24652 kB

15、顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶;

[root@localhost ~]# grep -E "/sbin/nologin$" /etc/passwd |cut -d: -f1
bin
daemon
adm
lp
mail
operator
games
ftp
nobody
avahi-autoipd
systemd-bus-proxy
systemd-network
dbus
polkitd
tss
postfix
sshd
mysql
nologin

16、顯示/etc/passwd文件中其默認shell為/bin/bash的用戶;

[root@localhost ~]# grep -E "/bin/bash$" /etc/passwd |cut -d: -f1
root
mageia
clouds
openstack
hadoop
bash
testbash
basher

17、找出/etc/passwd文件中的一位數或兩位數;

[root@localhost ~]# grep -E "\<[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
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

原創文章,作者:胡安慧,如若轉載,請注明出處:http://www.www58058.com/67402

(0)
胡安慧胡安慧
上一篇 2017-02-02 20:33
下一篇 2017-02-03 14:28

相關推薦

  • 關于TCP/IP與OSI模型基礎學習

    關于TCP/IP與OSI模型基礎學習 §·OSI七層模型介紹 OSI(Open system interconnection 開放系統互聯),七層網絡模型稱為開放式系統互聯參考模型 ,是一個邏輯上的定義,一個規范,它把網絡從邏輯上分為了7層。每一層都有相關、相對應的物理設備,比如路由器,交換機。OSI 七層模型是一種框架性的設計方法 ,建立七層模型的主要目的…

    Linux干貨 2016-09-05
  • man的用法

    man的使用 man命令是Linux下的幫助指令,通過man指令可以查看Linux中的指令幫助、配置文件幫助和編程幫助等信息。 語法 man(選項)(參數) 選項 -a:在所有的man幫助手冊中搜索; -f:等價于whatis指令,顯示給定關鍵字的簡短描述信息; -P:指定內容時使用分頁程序; -M:指定man手冊搜索的路徑。 參數 數字:指定從哪本man手…

    Linux干貨 2018-03-04
  • 文本處理工具

    1.cat 主要三大功能: 1.一次顯示整個文件:cat filename 2.從鍵盤創建一個文件:cat > filename << EOF ….>EOF (只能創建新文件,不能編輯已有文件);cat向已經存在的文件追加內容:cat >> file <<EOF…>EOF 3.將幾…

    2017-07-29
  • 權限命令總結

    修改文件權限:chmod 1 2 3 4 [root@centos7 ~]# man chmod        chmod [OPTION]… MODE[,MODE]… FILE…    …

    Linux干貨 2016-08-04
  • CentOS 6上的防火墻策略的保存

    兩種iptables的策略保存的方法

    2018-02-27
  • MySQL常用字符函數

    MySQL常用字符函數簡介 CONCAT(S1,S2…Sn) 連接S1,S2…Sn為一個字符串 concat函數,把傳入的參數連接成為一個字符串。 例如: 把“aaa”、“bbb”、”ccc”3個字符串連接成一個字符串,“aaabbbccc”.另外任何與NULL進行連接的結果都將是NULL. >SELEC…

    Linux干貨 2017-05-01
欧美性久久久久