Linux基礎練習題(二)
阿新 • • 發佈:2018-07-04
smo grub 用戶名 banner bash sre 開頭 boot .bashrc 系統版本:
[root@centos67d1 ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)
[root@centos67d1 ~]# uname -r
2.6.32-573.el6.x86_64
[root@centos71d1 ~]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
[root@centos71d1 ~]# uname -r
3.10.0-229.el7.x86_64
1. 復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限
[root@centos67n1 ~]# cp -rv /etc/skel/ /home/tuser1 #註意:事先無需創建/home/tuser1目錄,否則這條命令會變成復制/etc/skel目錄到/home/tuser1目錄下 `/etc/skel/‘ -> `/home/tuser1‘ `/etc/skel/.bash_logout‘ -> `/home/tuser1/.bash_logout‘ `/etc/skel/.bashrc‘ -> `/home/tuser1/.bashrc‘ `/etc/skel/.bash_profile‘ -> `/home/tuser1/.bash_profile‘ [root@centos67n1 ~]# chmod -R go-rwx /home/tuser1 [root@centos67n1 ~]# ll -a /home/tuser1/ total 20 drwx------. 2 root root 4096 Jul 3 17:03 . drwxr-xr-x. 3 root root 4096 Jul 3 17:03 .. -rw-------. 1 root root 18 Jul 3 17:03 .bash_logout -rw-------. 1 root root 176 Jul 3 17:03 .bash_profile -rw-------. 1 root root 124 Jul 3 17:03 .bashrc
2. 編輯/etc/group文件,添加組hadoop
[root@centos67n1 ~]# grep ‘777‘ /etc/group
#這裏沒有grep到任何內容,表示“777”這個組ID沒有被占用;#註意:在centos6中系統組ID的範圍是1-499,登錄組是500-60000
[root@centos67n1 ~]# echo ‘hadoop:x:777:‘ >> /etc/group
[root@centos67n1 ~]# tail -1 /etc/group
hadoop:x:777:
3. 手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號;其家目錄為/home/hadoop
[root@centos67n1 ~]# grep ‘777‘ /etc/passwd
#首先還是要確認“777”這個UID有沒有被占用,沒有grep到,表示沒有被占用;#在centos6中,登錄用戶的UID範圍和登錄組GID範圍一樣是500-60000
[root@centos67n1 ~]# echo ‘hadoop:x:777:777::/home/hadoop:/bin/bash‘ >> /etc/passwd
[root@centos67n1 ~]# tail -2 /etc/passwd
fedora:x:500:500::/home/fedora:/bin/bash
hadoop:x:777:777::/home/hadoop:/bin/bash
4. 復制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其它用戶沒有任何訪問權限
[root@centos67d1 ~]# cp -rv /etc/skel/ /home/hadoop
`/etc/skel/‘ -> `/home/hadoop‘
`/etc/skel/.bash_profile‘ -> `/home/hadoop/.bash_profile‘
`/etc/skel/.bash_logout‘ -> `/home/hadoop/.bash_logout‘
`/etc/skel/.bashrc‘ -> `/home/hadoop/.bashrc‘
[root@centos67d1 ~]# chmod go= /home/hadoop/
[root@centos67d1 ~]# ll -d /home/hadoop/
drwx------. 2 root root 4096 Jul 4 13:55 /home/hadoop/
5. 修改/home/hadoop目錄及其內部所有文件的屬主為hadoop,屬組為hadoop
[root@centos67d1 ~]# chown -R hadoop:hadoop /home/hadoop/
[root@centos67d1 ~]# ll -a /home/hadoop/
total 20
drwx------. 2 hadoop hadoop 4096 Jul 4 13:55 .
drwxr-xr-x. 6 root root 4096 Jul 4 13:55 ..
-rw-r--r--. 1 hadoop hadoop 18 Jul 4 13:55 .bash_logout
-rw-r--r--. 1 hadoop hadoop 176 Jul 4 13:55 .bash_profile
-rw-r--r--. 1 hadoop hadoop 124 Jul 4 13:55 .bashrc
6. 顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用兩種方式
[root@centos67d1 ~]# grep -i "^s" /proc/meminfo
SwapCached: 0 kB
SwapTotal: 2031612 kB
SwapFree: 2031612 kB
Shmem: 188 kB
Slab: 69812 kB
SReclaimable: 10648 kB
SUnreclaim: 59164 kB
或 [root@centos67d1 ~]# grep "^[Ss]" /proc/meminfo
或 [root@centos67d1 ~]# grep "^\(S\|s\)" /proc/meminfo
或 [root@centos67d1 ~]# grep -E "^(S|s)" /proc/meminfo
7. 顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶
[root@centos67d1 ~]# grep -v "/sbin/nologin" /etc/passwd | cut -d: -f1
root
sync
shutdown
halt
centos
fedora
archlinux
hadoop
8. 顯示/etc/passwd文件中其默認shell為/bin/bash的用戶
[root@centos67d1 ~]# grep "/bin/bash" /etc/passwd | cut -d: -f1
root
centos
fedora
archlinux
hadoop
9. 找出/etc/passwd文件中的一位數或兩位數
[root@centos71d1 ~]# 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
或 grep "\<[0-9][0-9]\?\>" /etc/passwd
10. 顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行
[root@centos67d1 ~]# grep "^[[:space:]]\+" /boot/grub/grub.conf
root (hd0,0)
kernel /vmlinuz-2.6.32-573.el6.x86_64 ro root=/dev/
mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swapSYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-573.el6.x86_64.img
或 [root@centos67d1 ~]# grep "^[[:space:]]\{1,\}" /boot/grub/grub.conf
11. 顯示/etc/rc.d/rc.sysinit文件中以#開頭,後面跟至少一個空白字符,而後又有至少一個非空白字符的行
[root@centos67d1 ~]# grep "^#[[: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)
....
12. netstat -tan命令執行結果中以‘LISTEN’,後或跟空白字符結尾的行
[root@centos67d1 ~]# 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
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:25 :::* LISTEN
13. 用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin),而後找出當前系統上其用戶名和默認shell相同的用戶的信息
[root@centos67d1 ~]# grep "^\([^:]\+\>\).*\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:778:778::/home/bash:/bin/bash
nologin:x:781:781::/home/nologin:/sbin/nologin
Linux基礎練習題(二)