Linux用戶、組管理和正則表達式的基礎命令

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

[root@localhost skel]# cp -r /etc/skel /home/tuser1
[root@localhost skel]# ls -al /home/tuser1
total 12
drwxr-xr-x. 3 root root  70 Jul 19 22:39 .
drwxr-xr-x. 9 root root 100 Jul 19 22:38 ..
-rw-r--r--. 1 root root  18 Jul 19 22:38 .bash_logout
-rw-r--r--. 1 root root 193 Jul 19 22:38 .bash_profile
-rw-r--r--. 1 root root 231 Jul 19 22:38 .bashrc
drwxr-xr-x. 2 root root  59 Jul 19 22:39 skel
[root@localhost ~]# chmod -R go= /home/tuser1
[root@localhost ~]# ls -la /home/tuser1
total 16
drwx------.  3 root root   70 Jul 19 22:39 .
drwxr-xr-x. 14 root root 4096 Jul 20 00:51 ..
-rw-------.  1 root root   18 Jul 19 22:38 .bash_logout
-rw-------.  1 root root  193 Jul 19 22:38 .bash_profile
-rw-------.  1 root root  231 Jul 19 22:38 .bashrc
drwx------.  2 root root   59 Jul 19 22:39 ske

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

[root@localhost skel]# nano /etc/group

  GNU nano 2.3.1              File: /etc/group                                  

entadmin:x:5002:test
test2:x:4003:
distro:x:2016:
mageia:x:1100:
admins:x:5003:slackware
mariadb:x:994:
magedu:x:5000:gentoo,fedora
fedora:x:4005:
hadoop:x:5004:

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

[root@localhost ~]# nano /etc/passwd

  GNU nano 2.3.1             File: /etc/passwd                                  

test:x:4001:1000:shijl,hs,110,119:/var/tmp/gentoo:/bin/bash
fedors:x:4002:4002:Fedora Core:/home/fedors:/bin/tcsh
test2:x:4003:4003::/home/test2:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2016::/home/slackware:/bin/tcsh
mariadb:x:996:994::/home/mariadb:/sbin/nologin
gentoo:x:4004:1000::/users/gentoo:/bin/bash
fedora:x:4005:4005::/users/fedora:/bin/bash
hadoop:x:5004:5004::/home/hadoop:/bin/bash

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

[root@localhost ~]# cp -r /etc/skel /home/hadoop
[root@localhost ~]# chmod go= /home/hadoop
[root@localhost ~]# ls -dl /home/hadoop/
drwx------. 2 root root 59 Jul 19 23:16 /home/hadoop/

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

[root@localhost ~]# chown -R hadoop:hadoop /home/hadoop
[root@localhost ~]# ls -ld /home/hadoop/
drwx------. 2 hadoop hadoop 59 Jul 19 23:16 /home/hadoop/
[root@localhost ~]# ls -al /home/hadoop/
total 16
drwx------.  2 hadoop hadoop   59 Jul 19 23:16 .
drwxr-xr-x. 10 root   root   4096 Jul 19 23:16 ..
-rw-r--r--.  1 hadoop hadoop   18 Jul 19 23:16 .bash_logout
-rw-r--r--.  1 hadoop hadoop  193 Jul 19 23:16 .bash_profile
-rw-r--r--.  1 hadoop hadoop  231 Jul 19 23:16 .bashrc

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

[root@localhost ~]# grep "^[sS]" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              6844 kB
Slab:              64964 kB
SReclaimable:      26088 kB
SUnreclaim:        38876 kB
[root@localhost ~]# grep -i "^s" /proc/meminfo 
SwapCached:            0 kB
SwapTotal:       2097148 kB
SwapFree:        2097148 kB
Shmem:              6844 kB
Slab:              64964 kB
SReclaimable:      26088 kB
SUnreclaim:        38876 kB

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

[root@localhost ~]# grep -v "/sbin/nologin$" /etc/passwd | cut -d: -f1
root
sync
shutdown
halt
test
fedors
test2
mageia
slackware
gentoo
fedora
hadoop

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

[root@localhost ~]# grep "/bin/bash$" /etc/passwd | cut -d: -f1
root
test
test2
mageia
gentoo
fedora
hadoop

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
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/grub2/grub.cfg中以至少一個空白字符開頭的行

[root@localhost ~]# grep "^[[: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

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: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 ~]# useradd bash 
[root@localhost ~]# useradd testbash
[root@localhost ~]# useradd basher
[root@localhost ~]# useradd  -s /sbin/nologin nologin
[root@localhost ~]# grep "\(nologin\).*\1" /etc/passwd
nologin:x:5008:5008::/home/nologin:/sbin/nologin

原創文章,作者:N27_shijinlong,如若轉載,請注明出處:http://www.www58058.com/81918

(1)
N27_shijinlongN27_shijinlong
上一篇 2017-07-20 20:21
下一篇 2017-07-20 21:10

相關推薦

  • ?Nginx

    Nginx 概述 yum安裝Nginx 編譯安裝Nginx 主要文件路徑 主配置文件nginx.conf main block:全局配置段 http/https 協議相關配置段 性能優化初步 調試、定位問題的配置 events段配置 worker、method、accept_mutex http協議相關配置段 虛擬主機 基于PORT、IP、Server Na…

    Linux干貨 2016-10-24
  • Linux 文件管理、查看、編輯、查找命令及BASH特性

    1、文件管理類命令總結  (1)cp命令:copy                    源文件 :目標文件 :    &nbsp…

    Linux干貨 2016-10-17
  • 轉載:UEFI和BIOS對比

    傳統BIOS開機流程     從你按下主機機殼上的電源鍵,到進入作業系統的期間,儲存于主機板上那顆EEPROM(電氣可抹除暨可程式化唯讀記憶體)里的BIOS便會開始執行以下的工作: 1. 初始化:     當電腦打開,CPU會自行重置為初始狀態,準備運作。BIOS boot block(基本輸出輸入…

    Linux干貨 2016-05-01
  • N25-第六周博客作業

    請詳細總結vim編輯器的使用并完成以下練習題 1、復制/etc/rc.d/rc.sysinit文件至/tmp目錄,將/tmp/rc.sysinit文件中的以至少一個空白字符開頭的行的行首加#; [root@han ~]# cp /etc/rc.d/rc.sysinit /tmp [root@han ~]#&n…

    Linux干貨 2017-02-16
  • Linux基礎操作-week5

    1、顯示當前系統上root、fedora或user1用戶的默認shell; 方式一: # whoami root # echo $SHELL /bin/bash 方式二: #grep user1 /etc/passwd|awk -F “:” ‘{print $7}’ /bin/bash 2、找出/etc/rc.…

    Linux干貨 2016-11-27
  • N25第二周作業 文件管理類命令cp mv rm以及 bash特性之文件名通配

    Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。         文件管理類命令主要有cp, mv, rm          cp用于單個文件的復制,例如:  &nb…

    Linux干貨 2016-12-13

評論列表(1條)

  • 馬哥教育
    馬哥教育 2017-07-27 00:01

    總結的不錯,第一題、第四題和第五題可以歸納為一類題目來做,后面可以多總結;繼續加油~

欧美性久久久久