马哥教育网络班22期+第5周课程练习

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

[root@rhel677850 ~]# grep "^\(root\|fedora\|user1\)" /etc/passwd|awk -F: '{print $1,$7}'
root /bin/bash
[root@rhel677850 ~]# egrep "^(root|fedora|user1)" /etc/passwd|awk -F: '{print $1,$7}'
root /bin/bash

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

[root@rhel677850 ~]# egrep "[[: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() {
action_silent() {
strstr() {
confirm() {
get_numeric_dev() {
is_ignored_file() {
is_true() {
is_false() {
apply_sysctl() {
key_is_random() {
find_crypto_mount_point() {
init_crypto() {

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

[root@rhel677850 ~]# echo "/etc/passwd"|grep -o "[^/]\+$"
passwd
使用grep取路径名
[root@rhel677850 ~]# echo "/etc/passwd"|grep -o ".*/"
/etc/

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

[root@rhel677850 ~]# ifconfig | egrep -o "\<([1-9]|[1-9][0-9]|1[0-9][0-9]|[2[0-4][0-9]|25[0-5]])\>"

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

[root@rhel677850 ~]# ifconfig | egrep -o "(\<([1-9]|[1-9][0-9]|1[0-9][0-9]|[2[0-4][0-9]|25[0-5]])\>\.){3}\<([1-9]|[1-9][0-9]|1[0-9][0-9]|[2[0-4][0-9]|25[0-5]])\>"
10.31.78.50

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

[root@rhel677850 ~]# egrep "[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$"   mail.txt
zhangxialoa@mageedu.com
318810@qq.com

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

[root@rhel677850 ~]# ls -l /var | awk '/\<root mail\>/{print $NF}'

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

[root@rhel677850 ~]# find / -nouser -a -nogroup

进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;

[root@rhel677850 ~]# find / -nouser -a -nogroup

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

[root@rhel677850 ~]# find / -perm -222

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

[root@rhel677850 ~]# find /etc/ -size +1M -type f
/etc/pki/tls/certs/ca-bundle.trust.crt
/etc/selinux/targeted/modules/active/policy.kern
/etc/selinux/targeted/policy/policy.24
/etc/gconf/gconf.xml.defaults/%gconf-tree.xml

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

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

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

[root@rhel677850 ~]# find /usr/ -not \( -user root -o -user bin -o -user hadoop \)

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

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

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

[root@rhel677850 ~]# find /etc/ -mtime -7 -not \( -user root -o -user hadoop \)

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

(0)
zhangxiaolazhangxiaola
上一篇 2016-09-26
下一篇 2016-09-26

相关推荐

  • Linux程序包管理相关

    前言 首先说说一个软件的诞生过程: 程序员用编程语言写文本格式的源代码,但是计算机只能读懂二进制文件,那么就需要将源代码转换成二进制格式,这个过程称为编译。编译用的工具称为编译器,编译器有很多种,在Linux上常用gcc这个编译器。利用编译器,得到二进制格式的文件(二进制程序(Windows上.exe.msi,Linux.elf)、库文件、配置文件、帮助文件…

    Linux干货 2018-01-04
  • 网络班N22期第四周博客作业

    一、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 [root@bogon ~]# cp -r /etc/skel /home/tuser1 && chmod -R 60…

    Linux干货 2016-09-05
  • DNS and BIND 进阶

    主DNS服务器的ip地址:192.168.1.109 主DNS服务器主机名:bogon 正向区域名:sh.com 反向区域名:1.168.192.in-addr.arpa 正向区域文件名称:/var/named/sh.com.hosts 反向区域文件名称:/var/named/192.168.1.rev 配置主文件/etc/named.conf过程 1、编辑…

    Linux干货 2016-12-06
  • Liunx 磁盘管理

    我们先来了解一下在Linux中磁盘的命名方式 命名:/dev/DEV_FILE    Sd :表示SCSI硬盘    Sda:表示SCSI硬盘中第一块硬盘,b表示第二块,以此类推 在Linux上次磁盘主要有两种分区方式MBR和GPT MBR分区格式最多有4个分区,可以是4个主分区,或者3个主分区和1个扩展分区,第一个逻…

    2017-08-21
  • C语言的整型溢出问题

    整型溢出有点老生常谈了,bla, bla, bla… 但似乎没有引起多少人的重视。整型溢出会有可能导致缓冲区溢出,缓冲区溢出会导致各种黑客攻击,比如最近OpenSSL的heartbleed事件,就是一个buffer overread的事件。在这里写下这篇文章,希望大家都了解一下整型溢出,编译器的行为,以及如何防范,以写出更安全的代码。 什么是整型溢出 C语言…

    Linux干货 2016-06-03
  • 第三周作业

    博客具体内容请移步博客园: http://www.cnblogs.com/ITOps/p/6204549.html

    Linux干货 2016-12-20

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-27 09:56

    写的很好,看的出来很用心,不过还是要注意排版的问题,希望继续保持