马哥教育网络班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

相关推荐

  • 包管理及源码安装Apache

    一,概述 yum 仓库的安装 在/etc/yum.repos.d/目录下创建后缀名为repo的配置文件 [CentOS7] name= baseurl= gpgcheck= enabled= 配置文件基本包含的四个要求 安装及升级本地程序包: * localinstall rpmfile1 [rpmfile2] […] (用install替代) …

    Linux干货 2016-09-01
  • shell脚本之条件测试

    组合条件测试:在多个条件间实现逻辑运算     与:[ condition1 -a condition2 ]、condition1 && condition2     或:[ condition…

    Linux干货 2015-08-24
  • keepalived的实验:主主模型

    修改配置文件 [root@proxy1 ~]# vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived   global_defs { notification_email { root@localhost } notification_email_from k…

    2018-03-11
  • 第八周:网络基础知识和shell脚本练习

    1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别; 网桥:是连接两个局域网的基于MAC地址数据存储转发设备,工作于数据链路层 集线器:所有端口处于同一个广播域和冲突域中,带宽共享,工作于物理层 二层交换机:多端口网桥,一个端口一个冲突域,默认所有端口位于同一个广播域中,可以划分vlan,隔离广播域,带宽独享 三层交换机:具有路由功…

    Linux干货 2016-11-21
  • linux中权限管理

    权限的描述:           权限的意思就是用户拥有的对系统支配能力的大小在linux中是严格控制用户权限的,不同的用户给予不同的权限,权限应遵循能少给就尽量少给的原则从而增加系统的安全性。 进程安全上下文:    进程对问件访问权限的应用模型:进程的属主与文件的属主是否相同,如果相同…

    系统运维 2016-08-05
  • 关于Linux文件系统的的简单理解和认识-20160730

    关于Linux文件系统的的简单理解和认识 关于文件系统的运作,这与操作系统带的档案数据有关。例如Linux操作系统的档案权限(rwx)与文件属性(拥有者,群组,时间参数等)。文件系统通常会将这两部分的数据分别存放在不同的区块,权限与属性放置到inode中,至于实际数据则放置到date block区块中,另外,还有一个超级块区(super block)会记录整…

    Linux干货 2016-08-04

评论列表(1条)

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

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