cat /dev/urandom | tr -dc "[:alnum:]" | head -c 30
grep -o "\<[0-9]\+\.[0-9]\>" /etc/redhat-release
ifconfig eth0 | grep -o "[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}" | head -n 1
ifconfig eth0 | egrep -o "\<(([0-9]{1,3}){1,3}\.){3}[0-9]{1,3}" | head -n 1
df | grep "/dev/sd" | grep -o "[0-9]*%" | grep -o "[0-9]\+" | sort -n | tail -1
df | grep "/dev/sd" | grep -o "\<[0-9]\{1,3\}\>%" | grep -o "[0-9]\+"| sort -n |tail -n -1
cat /etc/passwd | sort -t: -k3 -nr | cut -d : -f1,3,7 | head -n 1
stat -c %a /tmp
stat /tmp|grep "Uid"|grep -o "\<[0-9]\+\>" | head -n 1
stat /tmp|grep "Uid" | cut -d / -f1|cut -d "(" -f2
- 统计当前连接到本机的每个远程主机的连接数,并按照从大到小排序
ss -nt | tail -n +2 | tr -s " " : | cut -d : -f6 |sort |uniq -c|sort -nr|head -n 1
- 显示 /etc/init.d/functions 里边所有的方法
grep ".*{$" /etc/init.d/functions | cut -d " " -f1
grep -o ".*()" /etc/init.d/functions
grep -o "^[[:alnum:]_]\+[[:space:]]*()" /etc/init.d/functions
- 显示/proc/meminfo中以大小写s开头的行
grep -o "^[Ss].*" /proc/meminfo
grep -i "^s.*" /proc/meminfo
- 显示/etc/passwd文件中不以/bin/bash结尾的行
grep -v "/bin/bash$" /etc/passwd
grep "^rpc\>" /etc/passwd | cut -d : -f7
grep -o "\<[0-9]\{2,3\}\>" /etc/passwd
- 显示Centos7的/etc/grub2.cfg文件中,至少以一个空白字符开头且后边存在非空白字符的行
grep "^\s\+[^[:space:]]" /etc/grub2.cfg
- 找出 "netstat -tan"命令的结果中以 'LISTEN' 后跟任意多个空白字符结尾的行
netstat -tan | grep "LISTEN[[:space:]]*$"
cut -d: -f1,3 /etc/passwd | grep "\<[[:digit:]]\{,3\}$"
- 利用df和grep,取出磁盘各分区利用率,并从大到小排序
df |grep "^/dev/sd" |grep -o "[0-9]\{,3\}\%" | grep -o "[0-9]\{,3\}" | sort -nr
- 显示root、bin、daemon 三个用户的UID和默认shell
grep "^root\|^bin\|^daemon" /etc/passwd | cut -d : -f1,7
- 找出/etc/rc.d/init.d/functions文件中行首为某单词(包括下划线)后面跟一个小括号的行
grep "^[[:alpha:]_]\+\>()" /etc/rc.d/init.d/functions
- 使用egrep取出 /etc/rc.d/init.d/functions路径的目录名
echo "/etc/rc.d/init.d/functions" | egrep -o "^/.*/" | egrep -o "^/.*[^/]"
- 统计last命令中以root登录的每个主机IP地址登录次数
last | grep "^root" | tr -s " " | cut -d " " -f3 | grep -o "\([0-9]\{,3\}\.\)\{3\}[0-9]\{,3\}" | uniq -c | sort -n
last | grep "^root" | tr -s " " | cut -d " " -f3 | egrep "([0-9]+.){3}[0-9]+" | uniq -c
ifconfig | egrep -o "([0-9]+\.){3}[0-9]{1,3}"