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

相关推荐

  • 初识路由以及小实验

    路由(routing)就是通过互联的网络把信息从源地址传输到目的地址的活动。路由发生在OSI网络参考模型中的第三层即网路层。 初识路由以及小实验 根据实验的目的要求画出实验拓扑图 准备实验环境 根据实验拓扑图开始配置 配置计算机的IP: 配置路由器R1和R2的IP 配置路由 实验目的 实验准备 实验步骤 验证实验结果 实验目的 为了更好的了解路由,通过一个小…

    Linux干货 2016-11-24
  • sed命令及vim编辑器

    sed[option]… 'script' inputfile…选项:-n:不输出模式空间内容的自动打印-e: 多点编辑-f /PATH/TO/SCRIPT_FILE: 从指定文件中读取编辑脚本-r: 支持使用扩展正则表达式-i: 原处编辑script:'地址命令' 1.地址定界:(1) 不给地…

    Linux干货 2016-08-11
  • Shell脚本编程入门

    认识Shell Shell原意为贝壳 Linux系统中的shell是一个特殊的应用程序,它介于操作系统内核与用户之间,充当一个“命令解释器”的角色,负责接收用户输入的操作指令(命令)并进行解释,将需要执行的操作传递给内核执行,并输出执行结果。 可以使用命令查看当前使用的是哪种shell以及当前Linux系统中都支持哪些shell种类。   查看当前…

    Linux干货 2016-08-12
  • Linux入门知识之计算机基础

    计算机基础、linux发行版、命令帮助获取

    2018-01-11
  • kickstart+ftp+dhcp+tftp实现centos6的无人值守安装

    环境IP : 172.16.0.32 centos 6.6 一.安装相关包 安装图形界面 [root@localhost ~]# yum groupinstall “Desktop” “X Window System” “Chinese Support” [root@localhost ~]# yum -y install dhcp tftp-server …

    Linux干货 2017-06-03
  • 初入linux

    一、认识linux 1、在windows中通过盘符区分文件存放位置,而linux中没有盘符之说,只有文件和文件夹 2、在linux中,万物从根开始,没有后缀之说 二、文件系统的目录结构 /:根目录 /boot:系统启动的相关配置文件 /dev:设备文件 块设备:随机访问,数据块为单位 字符设备:线性访问,按字符为单位 设备号:主设备号(major)和次设备号…

    Linux干货 2017-05-20

评论列表(1条)

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

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