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)
上一篇 2016-12-26 16:24
下一篇 2016-12-26 16:50

相关推荐

  • Linux运维之进程管理

    一、      进程概念 进程是内核的一个功能,在Linux中,运行一个程序或命令可以出发一个事件而驱动一个PID,在linux系统中,系统只识别二进制程序文件,我们可以通过执行系统上的二进制程序来运行程序,进而产生进程。在linux系统中第一个进程是init程序,它是系统开机第一个加载的程序,用来支撑系统的…

    Linux干货 2016-09-13
  • 8.网络基础知识

    1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。 网桥:网桥就是把2个不同的网段桥接起来;可隔离冲突域。 集线器:集线器就是把多根以太网线或光纤集合连接在同一段物理介质下的装置;工作在物理层;不能隔离冲突域。 二层交换机:工作于OSI模型的第2层(数据链路层),故而称为二层交换机。二层交换技术的发展已经比较成熟,二层交换机属数据…

    Linux干货 2017-08-21
  • Linux部分命令及通配符用法

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

    2017-03-28
  • shell编程之函数

    函数:函数function是由若干条shell命令组成的语句块,实现代码 重用和模块化编程      1)函数的定义: 可在 命令行,脚本的一部分,只有函数的单独文件 中定义        两部分组成:函数名和函数体;函…

    Linux干货 2016-08-21
  • linux哲学思想

    有关运维,在哲学上的思想。 正确的哲学思想在我看来就是公理,就是像1+1=2一样大家都必须得遵守的公理。 当然,所有的公理都是有前提的,而有关linux的哲学思想当然是在linux环境这个大前提下。才是公理。在我看来,公理就是在学习知识之前所要依靠的准则,linux下的一切都在这些准则下。 比如: 一切接文件  linux下所有都是以文件的形式保存…

    2017-07-22
  • 马哥教育网络班21期-第八周课程练习

    1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。 网桥:是将广播域划分为多个小的冲突域,但广播域没有变。工作在OSI模型的数据链路层,端口很少;基于软件;可以处理上层事务。集线器:对接收到的信号进行再生整形放大,扩大网络传输距离;属于纯硬件网络底层设备,工作在OSI模型的物理层,不具有交换机的”智能记忆”和”学习”的能力;也不具…

    Linux干货 2016-08-29

评论列表(1条)

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

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