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

相关推荐

  • 详解用户,组,权限管理

    详解用户,组,权限管理 M21-陆东贵 测试环境:CentOS 7.2 内容介绍: 我们要使用操作系统进行工作,就需要人机交互操作,这时候计算机就需要创建用户,通过用户来实现操作,而且随着用户的增加需要给用户分组,这时候就需要对文件进行权限管理。 需要使用的工具:       用户相关工具:useradd; …

    Linux干货 2016-10-25
  • SQL优化大全

    1. 优化SQL步骤 1. 通过 show status和应用特点了解各种 SQL的执行频率        通过 SHOW STATUS 可以提供服务器状态信息,也可以使用 mysqladmin extende d-status 命令获得。 SHOW STATUS 可以根据需要显示 session 级别的统计结果和 g…

    Linux干货 2015-04-13
  • 文件权限

    文件权限 文件属性       rw-r–r–表示文件权限     Root 表示文件所有者     Root 表示文件所属组     0 表示文件的大小 …

    Linux干货 2016-08-11
  • 马哥教育网络班第21期+第四周课程作业

    1. 复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 cp -r /etc/skel /home/tuser1 chmod –R 700 /home/tuser1 2. 编辑/etc/group文件,添加组hadoop。 echo &q…

    Linux干货 2016-08-01
  • vim编辑器

      Linux文本编辑器vim     Linux下的编辑器最常用的就是vim或者vi文本编辑。vi和vim编辑器的区别是vim是vi的改进版本,在vi编辑器的基础上上扩展了很多实用的功能。 vim的使用 用vim打开文件:     vim [options] [file ..]…

    Linux干货 2016-12-04
  • N28-第一周

    1. 描述計算機的組成及其功能。
    2. 按系列羅列Linux的發行版,並描述不同發行版之間的聯繫與區別。
    3. 描述Linux的哲學思想,並按照自己的理解對其進行解釋性描述。
    4.說明Linux系統上命令的使用格式;詳細介紹ifconfig、echo、tty、startx、export、pwd、history、shutdown、poweroff、reboot、hwclock、date命令的使用,並配合相應的示例來闡述。
    5.如何在Linux系統上獲取命令的幫助信息,請詳細列出,並描述man文檔的章節是如何劃分的?
    6.請羅列Linux發行版的基礎目錄名稱命名法則及功能規定。

    Linux干货 2017-12-04

评论列表(1条)

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

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