本週作業聚焦於 egrep 正則匹配與 find 檔案查找的綜合應用,以下逐題解析。
# egrep '^(root|fedora|user1)' /etc/passwd | cut -d: -f1,7
# awk -F: '/root|fedora|user1/{print $1" ",$7}' /etc/passwd# egrep -o '\<[[:alpha:]]+\>\(\)' /etc/rc.d/init.d/functions
# echo /etc/sysconfig/network-scripts/ifcfg-eth0 | grep -o '^/.*/' ### 路徑名 # echo /etc/sysconfig/network-scripts/ifcfg-eth0 | grep -o '[^/]\+$' ### 基名
# ifconfig | egrep -o '[1-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-9]'
# ifconfig | egrep -o '(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-9])\.){3}[0-9]{1,3}'# egrep -o '[[:alnum:]]+@[[:alnum:]]+(\.[a-z]+){1,}' /tmp/mailtest# find /var/ -user root -a -group mail -ls
# find / -nouser -o -nogroup
# find /etc/ -perm -222
# find /etc/ -size +1M -type f
# find /etc/init.d/ -perm -113 -ls
# find /usr/ -not \( -user root -o -user bin -o -user hadoop \)
# find /etc/ ! -perm -222
# find /etc/ -mtime -7 -not \( -user root -o -user hadoop \)
這些題目涵蓋了正則表達式的字元匹配、邊界處理,以及 find 依屬主、權限、大小、時間進行精準查找的經典用法。