我正在嘗試寫出 /etc 目錄下所有其他用戶可執行且名稱以數字開頭或結尾的所有內容的名稱串列。
find /etc "(" -name "[0-9]*" -o -name "*[0-9]" ")" -perm -o=x -print
但每次我得到一個錯誤的答案,你能幫忙嗎?
uj5u.com熱心網友回復:
如果您使用的是zshshell,則可以使用高級檔案名生成 globbing獲取該檔案串列;不需要外部程式。特別是,使用遞回 glob、交替和匹配世界可執行檔案的glob 限定符:
zsh$ printf "%s\n" /etc/**/([0-9]*|*[0-9])(X)
/etc/alternatives/animate-im6
/etc/alternatives/c89
/etc/alternatives/c99
/etc/alternatives/compare-im6
/etc/alternatives/composite-im6
...
/etc/X11
/etc/X11/fonts/Type1
/etc/xdg/xdg-xubuntu/xfce4
/etc/xdg/xfce4
/etc/xfce4
做setopt glob_dots第一個匹配檔案名開頭。就像 find 一樣。否則他們會被跳過。
如果您正在使用find,則需要使用-mode引數來-perm選擇至少具有給定權限位的檔案(這實際上是您在問題中所擁有的并且對我有用)
find /etc \( -name "[0-9]*" -o -name "*[0-9]" \) -perm -o=x
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/324288.html
下一篇:Chdir滯后殼
