马哥教育网络21期+第5周练习博客

1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;

[root@localhost ~]# grep "^[[:space:]]\+" /boot/grub/grub.conf 
	root (hd0,0)
	kernel /vmlinuz-2.6.32-642.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
	initrd /initramfs-2.6.32-642.el6.x86_64.img

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

[root@localhost ~]# grep '^#[[: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.
....

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

[root@localhost ~]# netstat -tan | grep 'LISTEN[[:space:]]\+'
tcp        0      0 0.0.0.0:111                 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 127.0.0.1:25                0.0.0.0:*                   LISTEN      
tcp        0      0 0.0.0.0:46074               0.0.0.0:*                   LISTEN      
tcp        0      0 :::111                      :::*                        LISTEN      
tcp        0      0 :::41268                    :::*                        LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 ::1:631                     :::*                        LISTEN      
tcp        0      0 ::1:25                      :::*                        LISTEN

4、添加用户bash, testbash, basher, nologin (此一个用户的shell为/sbin/nologin),而后找出当前系统上其用户名和默认shell相同的用户的信息;

[root@localhost ~]#useradd bash
[root@localhost ~]#useradd testbash
[root@localhost ~]#useradd basher
[root@localhost ~]#useradd -s /sbin/nologin nologin
[root@localhost ~]# grep --color=auto "^\([[:alnum:]]\+\>\).*\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
bash:x:3006:3006::/home/bash:/bin/bash
nologin:x:3009:3009::/home/nologin:/sbin/nologin

5、显示当前系统上root、fedora或user1用户的默认shell;

#!/bin/bash
for i in {root,fedora,user1};do
        reslut=`grep "^\" /etc/passwd | cut -d: -f7`
        echo "$i shell is $reslut"
done

6、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();

[root@localhost ~]# grep "\([[:alpha:]]\+\)()" /etc/rc.d/init.d/functions
fstab_decode_str() {
checkpid() {
__readlink() {
__fgrep() {
__kill_pids_term_kill_checkpids() {
__kill_pids_term_kill() {
__umount_loop() {
__source_netdevs_fstab() {
__source_netdevs_mtab() {
...

7、使用echo命令输出一个绝对路径,使用grep取出其基名;

[root@localhost ~]# echo "/etc/sysconfig/" | sed 's@^.*/\([^/]\+\)/\?$@\1@'
sysconfig

扩展:取出其路径名

[root@localhost ~]# echo "/etc/sysconfig/" | sed  's@[^/]\+/\?$@@' 
/etc/

8、找出ifconfig命令结果中的1-255之间数字;

[root@localhost ~]# ifconfig | grep --colour=auto -E -o "\|\|\|\"

9、挑战题:写一个模式,能匹配合理的IP地址;

ifconfig | grep --color=auto -E -o "(\.){3}\"|head -1

10、挑战题:写一个模式,能匹配出所有的邮件地址;

grep ".*@.*" mail

11、查找/var目录下属主为root,且属组为mail的所有文件或目录;

[root@localhost ~]# find /var/ -user root -a -group mail  -ls
394263    4 drwxrwxr-x   2 root     mail         4096 Jul 21 12:58 /var/spool/mail

12、查找当前系统上没有属主或属组的文件;

[root@localhost ~]# find / -nouser -o -nogroup
 进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;
[root@localhost ~]#useradd test
[root@localhost ~]#userdel test
[root@localhost ~]# find /  -nouser -a -nogroup -a -atime -3  -ls
3145729    4 drwx------   4 500      500          4096 Jul  5 14:55 /home/test
3145733    4 drwxr-xr-x   4 500      500          4096 Jul  5 14:17 /home/test/.mozilla
3145735    4 drwxr-xr-x   2 500      500          4096 Aug 18  2010 /home/test/.mozilla/extensions
3145734    4 drwxr-xr-x   2 500      500          4096 Aug 18  2010 /home/test/.mozilla/plugins
3145736    4 drwxr-xr-x   2 500      500          4096 Nov 12  2010 /home/test/.gnome2

13、查找/etc目录下所有用户都有写权限的文件;

[root@localhost ~]# find /etc/  -perm -222 -ls

14、查找/etc目录下大于1M,且类型为普通文件的所有文件;

[[root@localhost ~]# find /etc/  -size +1M -a -type f -ls

15、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;

[root@localhost ~]# chmod o+w /etc/init.d/sssd 
[root@localhost ~]# find /etc/init.d/ -perm -113 -ls 
918508    4 -rwxr-xrwx   1 root     root         2690 May 11 16:04 /etc/init.d/sssd

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

[root@localhost ~]# find /usr/ -not \( -user root -o -user bin -o -user hadoop \) -ls
1974438   12 -rwsr-xr-x   1 abrt     abrt        10296 May 12 04:43 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

17、查找/etc/目录下至少有一类用户没有写权限的文件;

[root@localhost ~]# find /etc/ -not -perm /222 -ls

18、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;

[root@localhost ~]#find /etc/ -user root -a -user hadoop -a -mtime -7 -ls

   

原创文章,作者:Net21_Lion,如若转载,请注明出处:http://www.178linux.com/23821

(0)
Net21_LionNet21_Lion
上一篇 2016-07-21
下一篇 2016-07-22

相关推荐

  • TIME_WAIT引起Cannot assign requested address报错

    1.  问题描述      有时候用redis客户端(php或者java客户端)连接Redis服务器,报错:“Cannot assign requested address。”      原因是客户端频繁的连接服务器,由于每次连接都在很短时间内结束,导致很多的TIME_WAIT。所以新的连…

    Linux干货 2016-03-09
  • 我们都在前行的路上

    我们都在前行的路上         从0到1是一种突破,年少轻狂到心有余而力不足,力挽狂澜到恬淡人生需伏地脚踏实地地前行,漂泊在一线都市,立足我图网,途径百胜,一次机缘巧合转战阿里,对于一个工作6年的弄潮儿,他将所有经历的化作前行的动力和坚韧不拔的耐力,也许不经意,但却理所当然,…

    Linux干货 2016-11-03
  • linux用户组和权限管理

    用户组和权限管理  概念 用户分为三类: 1、超级用户:root uid=0,简单来说uid为0的用户就是超级用户。 2、虚拟用户:存在linux中,满足文件或者程序运行的需要,而创建的。不能登录,不能使用。uid=1-499,1-999(centos7) 3、普通用户:管理员root创建的用户。uid=500+,1000+(centos7) 用户…

    Linux干货 2017-07-29
  • 随笔

                        bash基础特性整理以及shell编程的思路整理       在lin…

    2016-07-07
  • 马哥教育网络班22期第6周课程作业

    请详细总结vim编辑器的使用并完成以下练习题 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; %s@^[[:space:]]\+@# 2、复制/boot/grub/grub.conf至/tmp目录中,删除/tmp/grub.conf文件中的行首的空白字符; %…

    Linux干货 2016-12-05

评论列表(1条)

  • 马哥教育
    马哥教育 2016-07-22 11:16

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