馬哥教育網絡班21期+第5周作業

1、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行(以/boot/grub2/grub.cfg代替);

[root@localhost ~]# grep '^[[:space:]]\+' /boot/grub2/grub.cfg 
  load_env
   set default="${next_entry}"
   set next_entry=
...內容略

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

[root@localhost ~]# cat /etc/rc.d/init.d/functions | grep '^#[[:space:]]\+[^[:space:]]\+' 
# -*-Shell-script-*-
# functions     This file contains functions to be used by most or all
#               shell scripts in the /etc/init.d directory.
# Make sure umask is sane
# Set up a default search path.
# Get a sane screen width

3、打出netstat -tan命令執行結果中以‘LISTEN’,后或跟空白字符結尾的行;

[root@localhost ~]# netstat -tan | grep 'LISTEN[[:space:]]*'
tcp        0      0 192.168.122.1:53        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:25            0.0.0.0:*               LISTEN     
tcp6       0      0 :::80                   :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN

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

[root@localhost ~]# useradd bash && useradd testbash && useradd basher && useradd -d /sbin/nologin nologin
[root@localhost ~]# 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
123:x:1111:1111::/123:/123
bash:x:1129:1129::/home/bash:/bin/bash
nologin:x:1130:1130::/home/nologin:/sbin/nologin

5、顯示當前系統上root、fedora或user1用戶的默認shell;

[root@localhost ~]# cat /etc/passwd |  grep '^\(root\|fedora\|user1\):' | cut -d: -f1,7
root:/bin/bash
user1:/bin/bash

6、找出/etc/rc.d/init.d/functions文件中某單詞后面跟一組小括號的行,形如:hello();

[root@localhost ~]# cat  /etc/rc.d/init.d/functions | grep '^[[:alpha:]]\+()'
checkpid() {
daemon() {
killproc() {
pidfileofproc() {
pidofproc() {
status() {
success() {
failure() {
passed() {
warning() {
action() {
strstr() {

7.1、使用echo命令輸出一個絕對路徑,使用grep取出其基名;

[root@localhost ~]# echo '/etc/ppp' | grep -o '^.*[^/]' | grep -o '/[^/]\+/\?$'   
/ppp

7.2、擴展:取出其路徑名

[root@localhost ~]# echo '/etc/ppp' | grep -o '^.*[^/]' | grep -o '^.*/'     
/etc/

8、找出ifconfig命令結果中的1-255之間的數字

[root@localhost ~]# ifconfig | egrep   '\<([1-9][1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>'
        inet 1.1.1.117  netmask 255.255.255.0  broadcast 1.1.1.255
        RX packets 1970  bytes 223843 (218.5 KiB)
        TX packets 1264  bytes 225028 (219.7 KiB)
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        RX packets 4  bytes 340 (340.0 B)
        TX packets 4  bytes 340 (340.0 B)
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255

9、挑戰題:寫一個模式,能匹配合理的IP地址

[root@localhost ~]# ifconfig | grep -o  --color '\(\([0-9]\|[1-9][0-9]\|1[0-9]\{2\}\|2[0-4][0-9]\|25[0-5]\)\.\)\{3\}\([0-9]\|[1-9][0-9]\|1[0-9]\{2\}\|2[0-4][0-9]\|25[0-5]\)'
1.1.1.117
255.255.255.0
1.1.1.255
127.0.0.1
255.0.0.0
192.168.122.1
255.255.255.0
192.168.122.255

10、挑戰題:寫一個模式,能匹配出所有的郵件地址;

[root@localhost ~]# echo '372564854@qq.com' >> 1.txt
[root@localhost ~]# echo '12345678@qq.com' >> 1.txt         
[root@localhost ~]# echo 'lich9978@qq.com' >> 1.txt        
[root@localhost ~]# cat 1.txt 
372564854@qq.com
12345678@qq.com
lich9978@qq.com
[root@localhost ~]# cat 1.txt | grep '^[a-zA-Z0-9_-]\+@[a-zA-Z0-9_-]\+\(\.[a-zA-Z0-9_-]\+\)\+$'
372564854@qq.com
12345678@qq.com
lich9978@qq.com

11、查找/var目錄下屬主為root,且屬組為mail的所有文件或目錄;

[root@localhost ~]# find /var -user root -group mail
/var/spool/mail

12、查找當前系統上沒有屬主或屬組的文件;

[root@localhost ~]# find / \( -nouser -o -nogroup \) -a -atime -3
find: ‘/proc/3745/task/3745/fd/6’: 沒有那個文件或目錄
find: ‘/proc/3745/task/3745/fdinfo/6’: 沒有那個文件或目錄
...內容略
/home/nologin/.mozilla/extensions
/home/nologin/.mozilla/plugins
[root@localhost ~]#

13、查找/etc目錄下所有用戶都有寫權限的文件

[root@localhost etc]# find /etc -perm -g+w,u+w,o+w
/etc/mtab
/etc/pki/java/cacerts
/etc/pki/tls/cert.pem
...略
/etc/httpd/run
/etc/1.txt

14、查找/etc目錄下大于1M,且類型為普通文件的所有文件;

[root@localhost etc]# find /etc -size +1M -type f
/etc/udev/hwdb.bin
/etc/selinux/targeted/policy/policy.29
/etc/brltty/zh-tw.ctb

15、查找/etc/init.d/目錄下,所有用戶都有執行權限,且其它用戶有寫權限的文件;

[root@localhost etc]# find /etc/init.d -perm -g+x,o+wx,u+x
/etc/init.d

16、查找/usr目錄下不屬于root、bin或hadoop的文件

[root@localhost etc]# find /usr -not \( -user root -o -user bin -o -user hadoop \)
/usr/share/polkit-1/rules.d
/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

17、查找/etc目錄下至少有一類用戶沒有寫權限的文件

[root@localhost etc]# find /etc/ ! -perm -444                                       
/etc/crypttab
/etc/pki/CA/private
...內容略
/etc/libvirt/nwfilter
/etc/gssproxy/gssproxy.conf

18、查找/etc目錄下最近一周內其內容被修改過,且不屬于root或hadoop的文件;

[root@localhost etc]# chown basher 1.txt
[root@localhost etc]# ll 1.txt 
-rw-rw-rw-. 1 basher root 0 8月   7 21:11 1.txt
[root@localhost etc]# find /etc ! -user root ! -user hadoop  -ctime -7           
/etc/1.txt

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

(0)
lichenhanlichenhan
上一篇 2016-08-08 16:11
下一篇 2016-08-08 16:11

相關推薦

  • 單用戶模式破解密碼與密碼的加密

    當你坐在一臺CentOS 6主機前,但是卻不知道密碼,要怎樣破解掉密碼進入系統呢? 答案很簡單: 1、啟動系統,當出現如下界面時,按任意鍵 2、你會看到這個畫面 3、敲擊“a”鍵,執行modifiy the kernel arguments 4、鍵入“1”鍵,進入單用戶模式 5、至此,你已經成功進入系統,并修改了密碼! 是不是覺得Centos6的系統這樣安全…

    Linux干貨 2016-09-13
  • Linux下/proc目錄詳解

    Linux下/proc目錄詳解 proc目錄總的概述 proc下有關進程的目錄概述 proc下針對Linux系統相關的參數目錄概述 /proc目錄總的概述 1.首先,我們可以使用ll命令查看下/proc目錄,如下 [root@centos6 ~]# ls -l /proc total 0 dr-xr-xr-x. 8 root root 0 May 19 04…

    Linux干貨 2017-05-20
  • 進程管理工具

    進程管理工具 kill man 7 signal 1) SIGHUP: 無須關閉進程而讓其重讀配置文件 kill -1 進程編號 2) SIGINT: 中止正在運行的進程;相當于Ctrl+c 9) SIGKILL: 殺死正在運行的進程 再生進程 kill -9 殺不掉 15) SIGTERM:終止正在運行的進程 kill -15/或不寫(默認) +進程編號?!?/p>

    Linux干貨 2016-09-11
  • 第二周

    第二周 1. Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。 cp 復制文件和目錄語法格式:cp [OPTION]… [-T] SOURCE DESTcp [OPTION]… SOURCE… DIRECTORYcp [OPTION]… -t DIRECTORY SOURCE&#8230…

    Linux干貨 2017-07-21
  • linux基礎之用戶管理

    介紹了一些基礎命令,比如cut、head傳輸到管道時的使用,并通過詳細的介紹、大量的習題完成了用戶管理的相關知識

    Linux干貨 2017-12-15
  • nginx配置文件中文文檔

    Nginx配置參數中文說明。 #定義Nginx運行的用戶和用戶組user www www; #nginx進程數,建議設置為等于CPU總核心數。worker_processes 8; #全局錯誤日志定義類型,[ debug | info | notice | warn | error | crit ]error_log /var/log/nginx/error…

    Linux干貨 2017-08-08

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-08-08 17:00

    寫的很好,排版也很棒,加油

欧美性久久久久