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

相关推荐

  • 常见RAID级别

    什么是RAID?     独立磁盘冗余阵列(RAID,Redundant Arrary of Independent Disks),旧称廉价磁盘冗余阵列(Redundant Arrary of Inexpensive Disks),简称磁盘阵列。基本思想就是把多个相对便宜的硬盘组合起来,成为一个硬盘阵列组,使性能达到甚至超过一个价格昂贵、…

    Linux干货 2016-05-29
  • 【职位推荐】华图网校/北京/运维工程师/8-12k(14薪)

    北京华图宏阳网络科技有限公司 华图教育集团:       华图教育(www.huatu.com)是华图宏阳股份旗下品牌,拥有遍布全国的100余家分支机构。主要产品包括中央和地方公务员招录考试辅导,事业单位、三支一扶、村官、选调生、招警等考试辅导。      北京华图宏阳教育文化发展股份有限…

    Linux干货 2016-04-20
  • 权限管理

    linux文件权限:     在linux系统中,每个文件或目录都包含有相应的权限,这些权限决定了哪些用户或组能够对此文件做哪些操作,如读取、删除、写入等操作 文件权限分为三类:r,w,x     应用于文件:      &nbs…

    Linux干货 2016-08-07
  • 二进制安装mysql(mariadb)

    实验环境: ~]# lsb_release -a Distributor ID: CentOSDescription: CentOS Linux release 7.4.1708 (Core)Release: 7.4.1708Codename: Core 去官方下载mariadb: https://downloads.mariadb.org/ 本人将自己的文…

    2018-01-22
  • 马哥教育网络班21期-第一次课程作业

    计算机组成部分及其作用 1.总线 电子管道,携带信息字节并在各个部件间传输。分为地址总线,数据总线,控制总线。 CPU最大可寻址范围:2^N*M,  N为地址总线数量,M为数据总线数量。 2.I/O设备 I/O设备及输入输出设备,最常见的输入设备就是我们非常熟悉的键盘,鼠标,我们通过我们通过这些设备向计算机传达指令,让计算机完成我们想要它完成的工作…

    Linux干货 2016-06-29
  • 马哥教育21期网络班—第五周课程+练习

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; grep "^[[:space:]]\+" /boot/grub/grub.conf 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行; grep "…

    Linux干货 2016-07-29

评论列表(1条)

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

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