N25-第五周作業

第五周

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

[root@zf ~]# grep -E "^[[:space:]]+[[:alnum:]]+" /boot/grub/grub.conf      
    root (hd0,0)     
    kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=UUID=10c8f38a-aa7e-44ba-81e2-bddbb6689b7c rd_NO_LUKS  
      KEYBOARDTYPE=pc KEYTABLE=us rd_NO_MD.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet     
    initrd /initramfs-2.6.32-431.el6.x86_64.img

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

[root@zf ~]# grep -E "^#[[: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)
    # Configure kernel parameters
    # Set the hostname.
    # Sync waiting for storage.
    # Device mapper & related initialization
    # Start any MD RAID arrays that haven't been started yet
    # Remount the root filesystem read-write.
    # Clean up SELinux labels
    # If relabeling, relabel mount points.
    # Mount all other filesystems (except for NFS and /proc, which is already
    # mounted). Contrary to standard usage,
    # filesystems are NOT unmounted in single user mode.
    # The 'no' applies to all listed filesystem types. See mount(8).
    # Update quotas if necessary
    # Check to see if a full relabel is needed
    # Initialize pseudo-random number generator
    # Configure machine if necessary.
    # Clean out /.
    # Do we need (w|u)tmpx files? We don't set them up, but the sysadmin might...
    # Clean up /var.
    # Clean up utmp/wtmp
    # Clean up various /tmp bits
    # Make ICE directory
    # Start up swapping.
    # Set up binfmt_misc
    # Boot time profiles. Yes, this should be somewhere else.
    # Now that we have all of our basic modules loaded and the kernel going,
    # let's dump the syslog ring somewhere so we can find it later
    # create the crash indicator flag to warn on crashes, offer fsck with timeout
    # Let rhgb know that we're leaving rc.sysinit

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

[root@zf ~]# netstat -tan | grep -E "LISTEN[[:space:]]*$"
    tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      
    tcp        0      0 0.0.0.0:44177               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 0.0.0.0:10050               0.0.0.0:*                   LISTEN      
    tcp        0      0 127.0.0.1:9000              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 :::55769                    :::*                        LISTEN      
    tcp        0      0 :::3306                     :::*                        LISTEN

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

[root@zf ~]# useradd bash
[root@zf ~]# useradd testbash
[root@zf ~]# useradd basher
[root@zf ~]# useradd -s /sbin/nologin nologin

[root@zf ~]# shell=$(grep "basher" /etc/passwd | cut -d: -f7)
[root@zf ~]# grep "$shell"  /etc/passwd | cut -d: -f1  
    root
    aa
    mageia
    openstack
    hadoop
    bash
    testbash
    basher

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

[root@zf ~]# grep -E "^(root|fedora)\>" /etc/passwd | cut -d: -f1,7
    root:/bin/bash
    fedora:/bin/bash

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

[root@zf ~]# grep -E "[[:alpha:]]+\>\(\)" /etc/rc.d/init.d/functions 
    fstab_decode_str() {
    checkpid() {
    __readlink() {
    __fgrep() {
    __umount_loop() {
    __umount_loopback_loop() {
    __pids_var_run() {
    __pids_pidof() {
    daemon() {
    killproc() {
    pidfileofproc() {
    pidofproc() {
    status() {
    echo_success() {
    echo_failure() {
    echo_passed() {
    echo_warning() {
    update_boot_stage() {
    success() {
    failure() {
    passed() {
    warning() {
    action() {
    strstr() {
    confirm() {
    get_numeric_dev() {
    is_ignored_file() {
    is_true() {
    is_false() {
    apply_sysctl() {
    key_is_random() {
    find_crypto_mount_point() {
    init_crypto() {

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

[root@zf ~]# echo "/usr/local/nginx/sbin/" | grep -E -o "[[:alnum:]]+/?$" | grep -o "[[:alnum:]]*" 
    sbin

[root@zf ~]# echo "/usr/local/nginx/sbin/" | grep -E -o "[/[:alnum:]]+\>" | grep -E -o "^/[/[:alnum:]]+/"
    /usr/local/nginx/

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

[root@zf ~]# ifconfig eth0 | grep -E -o "\<[1-9]\>|\<[1-9][0-9]\>|\<1[0-9][0-9]\>|\<2[0-4][0-9]\>|\<25[0-5]\>"
    29
    33
    83
    56
    10
    10
    10
    20
    10
    10
    10
    255
    255
    255
    255
    64
    1
    4
    5
    3
    9

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

[root@zf tmp]# ifconfig | grep -E -o "\<((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[1-9][0-9]?|2[0-4][0-9]|25[0-4])\>"
    10.10.10.30
    10.4.2.3
    127.0.0.1

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

[root@zf tmp]# cat mail_test 
    12457@qq.com
     w2R3@163.com
            Zhang.45e@mageedu.com
            zd_jdf@pa-jd.com
     eijm8@weij.com.cn
            fjhiu@fngy.net

[root@zf tmp]# grep -E -o "\<[^[:space:]]*\>@\<[^[:space:]]*\>\.\<[^[:space:]]*\>" mail_test 
    12457@qq.com
     w2R3@163.com
            Zhang.45e@mageedu.com
            zd_jdf@pa-jd.com
     eijm8@weij.com.cn
            fjhiu@fngy.net

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

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

12、查找當前系統上沒有屬主或屬組的文件; 進一步:查找當前系統上沒有屬主或屬組,且最近3天內曾被訪問過的文件或目錄;

[root@zf ~]# find / \( -nouser -o -nogroup \)
    /var/spool/mail/mandriva
    /home/mandriva
    /home/mandriva/.gnome2
    /home/mandriva/.bash_profile
    /home/mandriva/.bash_logout
    /home/mandriva/.bashrc
    /home/mandriva/.mozilla
    /home/mandriva/.mozilla/extensions
    /home/mandriva/.mozilla/plugins

[root@zf ~]# find / \( -nouser -o -nogroup \) -a -atime -3
    /var/spool/mail/mandriva
    /home/mandriva
    /home/mandriva/.gnome2
    /home/mandriva/.mozilla
    /home/mandriva/.mozilla/extensions
    /home/mandriva/.mozilla/plugins

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

[root@zf ~]# find /etc/ -perm -222
    /etc/rc1.d
    /etc/init.d
    /etc/rc0.d
    /etc/httpd/modules
    /etc/httpd/run
    /etc/httpd/logs
    ...

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

[root@zf ~]# find /etc/ -size +2M -a -type f 
    /etc/selinux/targeted/policy/policy.24
    /etc/selinux/targeted/modules/active/policy.kern

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

[root@zf ~]# find /etc/init.d/ -perm -113

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

[root@zf ~]# find /usr/ -not \( -user root -o -user bin -o  -user hadoop \)    
    /usr/local/nginx/scgi_temp
    /usr/local/nginx/proxy_temp
    /usr/local/nginx/fastcgi_temp
    /usr/local/nginx/fastcgi_temp/1
    /usr/local/nginx/fastcgi_temp/1/00
    /usr/local/nginx/client_body_temp
    /usr/local/nginx/uwsgi_temp
    /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

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

[root@zf ~]# find /etc/ -not -perm  -222       
    /etc/
    /etc/rwtab
    /etc/cron.deny
    /etc/dnsmasq.d
    /etc/.pwd.lock  
    ...

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

[root@zf ~]# find /etc/ -mtime -7 -a -not \( -user root -o -user hadoop \) 
    /etc/yum.conf.bak

原創文章,作者:N25-深圳-尋覓,如若轉載,請注明出處:http://www.www58058.com/64833

(0)
N25-深圳-尋覓N25-深圳-尋覓
上一篇 2016-12-26 16:24
下一篇 2016-12-26 16:50

相關推薦

  • 文件查找工具—find命令總結

    描述:   find命令用來在指定目錄下查找文件。任何位于參數之前的字符串都將被視為欲查找的目錄名。如果使用該命令時,不設置任何參數,則find命令將在當前目錄下查找子目錄與文件。并且將查找到的子目錄和文件全部進行顯示。 說明:  工作特點:  查找速度略慢; 精確查找;實時查找;可能只搜索用戶具備讀取和執行權限的目錄…

    Linux干貨 2016-08-18
  • N28-第二周博客作業

    常用通配符
    *:表示任意長度的任意字符;

    ?:表示任意的單個字符;

    []:表示在指定范圍內的單個字符:[a-z];

    [^]:脫字符,是取反的意思,即在指定范圍以外的任意字符,如 [^0-9]表示除數字以外的一切字符。

    [:digit:] 表示所有的數字,相當于0-9

    [:lower:] 表示所有的小寫字母

    [:upper:] 表示所有的大寫字母

    [:alpha:] 表示所有的字母,

    [:alnum:] 相當于[0-9a-z]

    [:space:] 相當于空白字符

    [:punct:] 表示所有的標點符號

    1、Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。

    2、bash的工作特性之命令執行狀態返回值和命令行展開所涉及的內容及其示例演示。

    3、請使用命令行展開功能來完成以下練習:

    (1)、創建/tmp目錄下的:a_c, a_d, b_c, b_d

    (2)、創建/tmp/mylinux目錄下的:
    mylinux/
    ├── bin
    ├── boot
    │?? └── grub
    ├── dev
    ├── etc
    │?? ├── rc.d
    │?? │?? └── init.d
    │?? └── sysconfig
    │?? └── network-scripts
    ├── lib
    │?? └── modules
    ├── lib64
    ├── proc
    ├── sbin
    ├── sys
    ├── tmp
    ├── usr
    │?? └── local
    │?? ├── bin
    │?? └── sbin
    └── var
    ├── lock
    ├── log
    └── run

    4、文件的元數據信息有哪些,分別表示什么含義,如何查看?如何修改文件的時間戳信息。

    5、如何定義一個命令的別名,如何在命令中引用另一個命令的執行結果?

    6、顯示/var目錄下所有以l開頭,以一個小寫字母結尾,且中間至少出現一位數字(可以有其它字符)的文件或目錄。

    7、顯示/etc目錄下,以任意一個數字開頭,且以非數字結尾的文件或目錄。

    8、顯示/etc目錄下,以非字母開頭,后面跟了一個字母以及其它任意長度任意字符的文件或目錄。

    9、在/tmp目錄下創建以tfile開頭,后跟當前日期和時間的文件,文件名形如:tfile-2016-05-27-09-32-22。

    10、復制/etc目錄下所有以p開頭,以非數字結尾的文件或目錄到/tmp/mytest1目錄中。

    11、復制/etc目錄下所有以.d結尾的文件或目錄至/tmp/mytest2目錄中。

    12、復制/etc/目錄下所有以l或m或n開頭,以.conf結尾的文件至/tmp/mytest3目錄中。

    Linux干貨 2017-12-11
  • 02葵花寶典之bash特性及文件入門

    文件管理 目錄 命令替換 命令執行狀態 元數據 時間戳

    2018-03-11
  • N21-北京-兔鍋-馬哥教育網絡班21期+第3周課程練習

    1、列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。    who | cut -d' ' -f1 | uniq   2、取出最后登錄到當前系統的用戶的相關信息。    who | ta…

    系統運維 2016-07-07
  • 【25期】Linux第一周學習知識小結

    1:設置Linux圖形界面不用輸入賬號和密碼直接登錄系統 首先在圖形化界面編輯文件:vi /etc/gdm/custom.conf 編輯如下圖: 在[daemon]下添加兩行代碼: AutomaticLoginEnable=True // 自動登陸器用 AutomaticLogin=root   //登錄賬號root 2:free命令 在終端輸入f…

    2017-07-15
  • centos7上實現corosync V2 + pacemaker + pcs | crmsh備忘錄

    1、集群配置的前提: 一、時間同步(ntpdate做crontab定時任務) 二、主機名和IP相互解析 三、基于ssh密鑰主機互信 #ssh-keygen -t rsa #ssh-copy-id -i   集群的全生命周期管理工具: pcs: agent(pcsd) crmsh: agentless (pssh)     2、安…

    2017-11-15

評論列表(1條)

  • 馬哥教育
    馬哥教育 2017-02-17 11:01

    寫的很好,排版也很棒,繼續保持,加油。

欧美性久久久久