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)
dengjiandengjian
上一篇 2016-08-08
下一篇 2016-08-08

相关推荐

  • centos 7.3二进制安装mariadb10.2.8

    1 rpm -qa mariadb* 2 getent passwd mysql useradd -d /app/mysqldb -r -m -s /sbin/nologin mysql 3 tar xvf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local/cd /usr/local/ln -s mariadb…

    Linux干货 2017-10-16
  • lvs DR模型

    LVS 负载均衡 使用lvs部署负载均衡服务器  实现4层tcp调度 lvs一共四种模式   分别是NAT  DR  TUN和FullNAT模式 NAT模式和DR模式部署相对简单而且实用性强 现在部署一下  LVS的DR模型 首先准备三台主机  使用的三台系统都是centos 7…

    2017-05-15
  • SElinux管理

                                                      &nbsp…

    系统运维 2016-09-26
  • 磁盘管理之文件系统

                             文件系统     文件系统是操作系统用于…

    Linux干货 2016-09-06
  • 正则表达式常用元字符

    正则表达式的使用需要借助于工具程序来实现,我们使用grep来演示正则表达式元字符的使用。     grep使用方法             grep是一种文本搜索工具,根据用户指定的文本模式(搜索条件…

    Linux干货 2015-03-10
  • 企业实时同步方案—-Sersync介绍

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1433109 Sersync 项目利用 Inotify 和 Rsync 技术实现对服务器数据实时同步的解决方案,其中 Inotify 用于监控 Sersync…

    Linux干货 2016-08-15