首页 技术 正文
技术 2022年11月18日
0 收藏 706 点赞 4,516 浏览 2730 个字
练习一
1、生成30位的随机口令
[root@centos7 ~]#cat /dev/urandom | tr -dc "[:alnum:]" | head -c30
RJL5qcA5PsQHnYE4kXui0oNkm1FNh12、判断主机版本号
[root@centos7 ~]#grep -o "[0-9]\+" /etc/centos-release | head -n1练习二
1、找出ifconfig “网卡名” 命令结果中本机的IPv4地址
ifconfig |egrep -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])\>"
2、查出分区空间使用率的最大百分比值
[root@centos7 ~]#df | grep "/dev/sd" | grep -o "[0-9]*%" | grep -o "[0-9]\+" | sort -n | tail -13、查出用户UID最大值的用户名、UID及shell类型
[root@centos7 app]#cat /etc/passwd | sort -nr -t: -k3 | head -n1 | cut -d: -f1,3,7
nfsnobody:65534:/sbin/nologin
4、查出/tmp的权限,以数字方式显示
方法一:
[root@centos7 app]#stat -c %a /tmp
1777方法二:
[root@centos7 app]#stat /tmp | grep Uid | cut -d\( -f2 | cut -d/ -f1
1777方法三
stat /tmp | grep Uid | cut -d\( -f2 | head -c45、统计当前连接本机的每个远程主机IP的连接数,并按从大到小排序显示文件/etc/init.d/functions所有方法
方法一
grep ".*{$" /etc/init.d/functions | tr -d { 方法二
[root@centos7 ~]#grep -o "^.*()" /etc/init.d/functions规范方法三
grep "^[[:alnum:]_]\+[[:space:]]*()" /etc/init.d/functions练习三
1、显示/proc/meminfo文件中以大小写s开头的行(要求:使用两种方法,不要理解以s开头的单词)
grep -i "^s.*" /proc/meminfo 方法一
grep "^[Ss].*" /proc/meminfo 方法二2、显示/etc/passwd文件中不以/bin/bash结尾的行
grep -v "/bin/bash$" /etc/passwd3、显示用户rpc默认的shell程序
grep "^rpc\>" /etc/passwd | cut -d: -f74、找出/etc/passwd中的两位或三位数
grep -o "\<[0-9]\{2,3\}\>" /etc/passwd 5、显示CentOS7的/etc/grub2.cfg文件中,至少以一个空白字符开头的且后面存非空白字符的行
grep "^[[:space:]]\+[^[:space:]]" /etc/grub2.cfg6、找出“netstat -tan”命令的结果中以‘LISTEN’后跟任意多个空白字符结尾的行
netstat -tan| grep "LISTEN[[:space:]]*$" 7、显示CentOS7上所有系统用户的用户名和UID
cut -d: -f1,3 /etc/passwd | grep "\<[[:digit:]]\{,3\}$"
"\<[[:digit:]]\{,3\}\>"(123用户名能匹配) 注意与上正则区别8、添加用户bash、testbash、basher、sh、nologin(其shell
为/sbin/nologin),找出/etc/passwd用户名同shell名的行
grep "^\(.*\):.*\<\1$" /etc/passwd9、利用df和grep,取出磁盘各分区利用率,并从大到小排序
df | grep "^/dev/sd" | grep -o "[0-9]\{1,3\}%" | grep -o "[0-9]\{1,3\}" | sort -rn练习四
1、显示三个用户root、mage、wang的UID和默认shell
[root@centos7 ~]#grep "^\(root\)\|^\(xiaojun\)\|^\(zilong\)" /etc/passwd | cut -d: -f3,7
0:/bin/bash
1001:/bin/bash
1011:/bin/bash2、找出/etc/rc.d/init.d/functions文件中行首为某单词(包括下划线)后面跟一个小括号的行
[root@centos7 ~]#grep -o "^[[:alpha:]]\+\>(" /etc/rc.d/init.d/functions
checkpid(
daemon(
killproc(
…..
3、使用egrep取出/etc/rc.d/init.d/functions中其基名echo "/etc/rc.d/init.d/functions" | egrep -o "[^/]+$"
扩展:取出/etc/rc.d/init.d/基名
[root@centos7 ~]#echo "/etc/rc.d/init.d/" | egrep -o "[^/]+/?$"
4、使用egrep取出/etc/rc.d/init.d/functions路径的目录名
[root@centos7 ~]#echo "/etc/rc.d/init.d/functions" | egrep -o "^/.*/" | egrep -o "^/.*[^/]" 5、统计last命令中以root登录的每个主机IP地址登录次数
last | grep "root" | tr -s " " ":" | cut -d : -f3 | egrep "([0-9]+.){3}[0-9]+" | uniq -c
6、利用扩展正则表达式分别表示
0-9:[0-9]
10-99 : [1-9][0-9]
100-199: 1[0-9][0-9]
200-249: 2[0-4][0-9]
250-255: 25[0-5]7、显示ifconfig命令结果中所有IPv4地址
[root@centos7 ~]#ifconfig ens33 | egrep -o "\<(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\>"
192.168.10.150
255.255.255.0
192.168.10.255
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,982
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,499
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,343
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,126
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,760
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,796