Linux 第七天: (08月05日) 练习和作业

Linux 第七天: (08月05日) 练习和作业

 

 

 

1 找出ifconfig命令结果中本机的所有IPv4地址

ifconfig | tr -cs '[0-9].''\n' | sort -ut '.' -k3 -n 或
ifconfig | head -2 | tail -1 | cut -d: -f2 | cut -d " " -f1

 

2 查出分区空间使用率的最大百分比

df -h |tr -s ' ' ':'|cut -d: -f5 |tr -d % | sort -n

 

3 查出用户UID最大值得用户名,UID及shell类型

getent passwd | sort -t: -k3 -nr|cut -d: -f1,3,7|tail -1

 

4 查出/tmp权限, 以数字显示

stat /tmp |head -4 |tail -1 |tr " " "\n" |head -2 |tail -1|tr -dc '[:digit:]'

 

5 统计当前连接本机的每个远程主机IP连接数, 从大到小排序

netstat -nt|tr -s ' ' '|' |cut -d '|' -f5 |cut -d: -f1 |uniq -c|sort -n

 

统计/etc/init.d/functiongs每个单词出现次数

cat /etc/init.d/functiongs | tr -cs '[:alpha:]''\n' | sort  | uniq -c | sort -n

 

扫描网段显示主机IP

nmap -sP -v 10.1.252.210/24 | grep -B1 up | grep -v up

 

1 显示/proc/meminfo 文件中以大小s开头的行 (两种方法)

grep '^[sS].*' /proc/meminfo 或
grep -i '^s.*' /proc/meminfo 或
grep -e '^s.*' -e '^S.*' /proc/meminfo

 

2 显示/etc/paswd 文件中不以/bin/bash结尾的行

grep -v /bin/bash& /etc/passwd

 

3 显示用户rpc默认的shell程序

grep '^rpc\>' /etc/passwd | cut -d : -f 7

 

4 找出/etc/passwd 文件中的两位或三位数

grep "\<[1-9][0-9][0-9]\?\>" /etc/passwd 或
grep "\<[1-9][0-9]\{1,2\}\>" /etc/passwd 或
grep -w "[1-9][0-9][0-9]\?" /etc/passwd

 

5 显示/etc/grup2.cfg文件中至少一个空白字符开头的且后面有非空白字符的行

grep "^[[:space]]\+[^[:space:]].*" /etc/grub2.cfg

 

6 找出"netstat -tan"命令结果中以'LISTEN'后跟任意空白字符结尾的行

netstat -tan | grep 'LISTEN[[:space]]]*$'

 

7 添加用户bash,testbash,basher,nologin(shell为/sbin/nologin),
  找出/etc/passwd文件中用户名同shell名的行

useradd bash
useradd testbash
useradd basher
useradd nologin -s /sbin/nologin
grep '^\<\(.*\)\>.*/\1$' /etc/passwd 或
grep '^\<\(.*\)\>.*\<\1\>$' /etc/passwd

 

1 显示root,mage,wang,的UID和默认shell

grep -E "^\<root\>|^\<mage\>|^\<wang\>" /etc/passwd|cut -d: -f3,7 或
grep -E "^(root|wang|mage)\>" /etc/passwd|cut -d: -f3,7 或
grep -E "^(root|wang|mage):" /etc/passwd|cut -d: -f3,7

 

2 找出/etc/rc.d/init.d/functions文件中行首为某单词(包括下划线)后面跟一个小括号的行

egrep "^[[:almum:]_]+\(\)" /etc/tc.d/init.d/functions|

 

3 使用egrep取出/etc/rcd/initd/functions中基名

echo "/etc/rc.d/init.d/functions" | egrep -o"[^/]+/?$"

 

4 使用egrep取出/etc/rcd/initd/functions目录名

echo "/etc/rc.d/init.d/functions" | egrep -o"(/.*/)"

 

5 统计以root身份登录的每个远程主机IP地址的登录次数

last | grep -E -o "^root\>.*([[:digit:]]\.){3}[[:digit:]]" |tr -s ' ' |cut -d' ' -f3 |sort |uniq -c

 

6 利用扩展正则表达式分别表示0-9,10-99,100-199,200-249,250-255

([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]

 

7 显示ifconfig命令结果中所有IPv4地址

ifconfig | grep -E -o
'(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])' 或

ifconfig | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'

 

正则表达式表示身份证号

^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$

 

正则表达式表示手机号

^[1][3|5|7|8][0-9]{9}$

 

正则表达式表示邮箱

^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$

 

正则表达式表示QQ号

[1-9][0-9]{5,11}

 

 

 

 

 

 

原创文章,作者:dengjian,如若转载,请注明出处:http://www.178linux.com/30894

(0)
上一篇 2016-08-08 09:22
下一篇 2016-08-08 09:22

相关推荐

  • DHCP及自动化安装Linux

    主机IP配置: 静态指定 静态IP 动态获取: bootp:bootprotocol MAC与IP一一静态对应 DHCP: Dynamic Host Configuration Protocol 动态主机配置协议基于UTP协议 主要用途:自动化分配IP地址,实现集中管理,解决IP地址不足的问题。 DHCP的4种报文 DHCP DISCOVER OFFER R…

    2017-09-18
  • linux用户和组及其配置

    LINUX用户和组概念及相关配置 1.   用户 我们在使用linux过程中,最直观的就是用户。用户就是我们要登录、操作的那个人。系统验证密码的过程就是在验证“你就是你”的过程。用户分为管理员和普通用户,计算机能识别的语言就是一堆的数字。你所看到的用户名计算机也会把它转化为数字,叫做ID号。管理员的ID为0,普通用户分为两种,一种是系统用…

    Linux干货 2016-10-24
  • Linux网站架构系列之Apache—-进阶篇

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1320167 本篇博文为Linux网站架构系列之apache的第二篇,我将带大家一起学习apache的编译参数,目录结构和配置文件等方面的知识,实现对apac…

    Linux干货 2016-08-15
  • N25第七周学习总结(CentOS 7 系统启动流程)

    CentOs系统启动流程 大纲 1、    什么是CentOs系统启动流程 2、    为什么要了解CentOS系统启动流程 3、    了解CentOS系统启动流程对我们有什么帮助 4、    CentOs系统启动流程详解   …

    Linux干货 2017-02-20
  • N25 _WSH 第二周

    2、bash 命令执行的状态结果:        * bash通过状态返回值来输出此结果:            * 成功:0            失败:1-255     &n…

    系统运维 2016-12-12
  • 条件选择if 条件判断case 文件查找 find locate 以及压缩和解压缩工具

    1 shell脚本编程之 条件选择if 条件判断case  2 文件查找 find locate 以及压缩和解压缩工具 过程式编程语言:  顺序执行  选择执行  循环执行 条件选择之 if语句 选择执行:   注意:if语句可嵌套    单分支 if 判断条件:then 条件为真的分…

    Linux干货 2016-08-15