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.178linux.com/64833

(0)
N25-深圳-寻觅N25-深圳-寻觅
上一篇 2016-12-26
下一篇 2016-12-26

相关推荐

  • Linux部分命令及通配符用法

    pwd: 显示工作目录 cd -: 在上一次所在目录与当前目录之间来回切换 cd: 切换回家目录 cat:  文本查看工具 n:给显示的文本行编号 -E:显示行结束符$ passwd 修改用户的密码 which 查看系统命令所对应的路径 df 查看系统分区 runlevel 查看系统运行级别  (共有6个级别) Tty…

    2017-03-28
  • vrrp_script高可用httpd&双主httpd

      vrrp_script高可用httpd 实验拓扑: HA01 192.168.150.137     MASTER HA02 192.168.150.137     BACKUP VIP 1921.168.150.131 实验1: 通过touch一个文件来控制keepalived主机的优先级 HA01的配…

    Linux干货 2016-12-06
  • 用户管理

    http://www.jianshu.com/p/a07ae29ca345

    Linux干货 2017-07-23
  • 高级文件系统管理1

    本部分内容主要讲述了高级文件系统的管理,包括设定文件系统配额,设定和管理软RAID设备,配置逻辑卷,设定LVM快照和btrfs文件系统。其中文件系统配额和软RAID在企业中使用的频率并不很高,作为熟练即可,而逻辑卷的创建和LVM快照是非常重要的内容,必须精通并完全理解其原理。至于btrfs文件系统是新兴的一种技术,作为了解即可。 一、知识整理 1、文件系统配…

    Linux干货 2016-08-29
  • 2018第六届中国网络安全大会即将于6月强势登陆!

    2018年6月13日,由赛可达实验室、国家计算机病毒应急处理中心、国家网络与信息系统安全产品质量监督检验中心、首都创新大联盟共同举办的第六届中国网络安全大会(NSC 2018)将在北京国家会议中心盛大召开。

    2018-03-15
  • 第二十六天 iptables 初识

      Iptables是位于用户空间,是linux系统上的防火墙管理配置规则的工具,主要用于添加、删除、管理netfilter的规则,   Netfilter是位于内核中真正的防火墙,由5个钩子组成,也叫五个规则链。 Netfilter的作用:起到过滤封包,转换与映射IP地址和端口,拆分和修改封包内容,追踪封包等功能 Iptabl…

    Linux干货 2016-07-02

评论列表(1条)

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

    写的很好,排版也很棒,继续保持,加油。