马哥教育网络班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 07:43
下一篇 2016-09-26 07:43

相关推荐

  • 系统自动化安装和SELinux

    一、知识整理 1、anaconda系统安装程序:默认图形启动; 使用光盘启动,在选择模式界面tab键在后面增加text或按下ESC键,输入lnux text进入字符界面安装。 2、创建kickstart文件: 直接手动编辑:依据模板修改,/root目录下的anaconda.cfg 使用创建工具创建:system-config-kickstart,图形化工具:…

    Linux干货 2016-09-26
  • 文件搜索之find的使用

    一.find介绍:   find是Linxu中一个十分常用的文件查找工具,其工作原理是通过遍历启起始路径下文件层级结构完成的,其特点是查找速度慢,能做到实时查找和精确查找。 二.使用方法: find  start_path search_conditions  action 1.statr_path:所要查找的文件的起始位置,默…

    Linux干货 2016-11-01
  • ansible基础应用

    Ansible基础 ansible是一款自动化运维工具,基于Python开发,实现了批量系统配置、批量程序部署、批量运行命令等功能。ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架。 Ansible架构简介 ansible的核心就是ansible平台,ansible是高度模…

    Linux干货 2016-08-22
  • linux系统启动之破坏与修复

    linux系统启动之破坏与修复:      通过这些实验,了解linux启动流程和相关文件,同时也预防系统发生问题能更快解决,而不用重装或者耽误时间:      实验:破坏MBR 446     dd if=/dev/zero of=/dev/sda bs=1 count=446…

    Linux干货 2017-03-30
  • linux磁盘管理补充之挂载选项及常用工具

    一、文件挂载的配置文件         配置文件:/etc/fstab 要挂载的设备的UUID或卷标或/dev/sd[a-z]    挂载点        &n…

    Linux干货 2016-08-30
  • Linux初探

    1.计算机组成: CPU:运算器(指令集)、控制器、寄存器、缓存; 存储器:内存,RAM; Input:下指令,提供数据; Ouput:输出数据加工的结果 一般来说,从磁盘中读取程序和数据放到内存中排队,由cpu从内存中读取执行。由于cpu处理速度远大于磁盘的I/O速度,因此引入缓存。在计算机中有缓存为王这个说法。 2.操作系统的背景: 1.统一规范 2.由…

    Linux干货 2016-10-30

评论列表(1条)

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

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