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
下一篇 2016-12-26

相關推薦

  • 關于大型網站技術演進的思考(三):存儲的瓶頸(3)

    原文出處: 夏天的森林    存儲的瓶頸寫到現在就要進入到深水區了,如果我們所做的網站已經到了做數據庫垂直拆分和水平拆分的階段,那么此時我們所面臨的技術難度的挑戰也會大大增強。 這里我們先回顧下數據庫的垂直拆分和水平拆分的定義: 垂直拆分:把一個數據庫中不同業務單元的數據分到不同的數據庫里。 水平拆分:是根據一定的規則把同一業務…

    Linux干貨 2015-03-03
  • 8-5作業

    1、取本機ip地址 ifconfig |grep -E -o  '(([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])' 2、取各分區利…

    Linux干貨 2016-08-08
  • 如何實現本地yum源的共享

    上一篇關于Linux yum客戶端的配置的博客,介紹了如何通過修改本機yum配置文件來訪問網絡或者本地的yun sever, 本文就來介紹一下,如何把我們的本地RPM包像yum sever一樣通過http或ftp網絡方式共享出去。 一、準備好發行版光盤,包,元數據    CentOS-6.8-x86_64-bin-DVD1.iso二、準備…

    2017-06-17
  • 編程能力與編程年齡

    程序員這個職業究竟可以干多少年,在中國這片神奇的土地上,很多人都說只能干到30歲,然后就需要轉型,就像《程序員技術練級攻略》這篇文章很多人回復到這種玩法會玩死人的一樣。我在很多面試中,問到應聘者未來的規劃都能聽到好些應聘都說程序員是個青春飯。因為,大多數程序員都認為,編程這個事只能干到30歲,最多35歲吧。每每我聽到這樣的言論,都讓我感到相當的無語,大家都希…

    Linux干貨 2016-08-15
  • 關于tar命令的一些方法

    tar 解壓縮文件時只有當文件格式中有tar才能使用,否則使用其他單獨的特定解壓縮工具,例如uncompress,gzip ,bzip2.xz等等 tar壓縮解壓縮命令詳解 tar命令詳解 -c: 建立壓縮檔案 -x:解壓 -t:查看內容 -r:向壓縮歸檔文件末尾追加文件 -u:更新原壓縮包中的文件 這五個是獨立的命令,壓縮解壓都要用到其中一個,可以和別的命…

    Linux干貨 2016-08-29
  • 馬哥教育20期面授2班第一周課程練習1

    計算機基礎   1,計算機系統           硬件系統            主機部分:中央處理器CPU(運算器ALU、控制器CU);  &nb…

    Linux干貨 2016-07-29

評論列表(1條)

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

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

欧美性久久久久