Linux:一種簡單而優雅的方式來尋找具有 acl 設定的所有檔案?

Linux:一種簡單而優雅的方式來尋找具有 acl 設定的所有檔案?

我想找到所有設定了 acl 的檔案。我知道這個骯髒的解決方案:尋找目錄中設定了 acl 的所有檔案。 /ETC

 sudo ls -lhR /etc|grep +

有人知道更優雅的解決方案嗎?

答案1

簡單和優雅是一個相當高的門檻,如果你的解決+方案中有檔名(例如 c++),你的骯髒解決方案就會失敗。

另一種方法是getfacl遞歸使用,跳過沒有 ACL 的文件

getfacl -Rs /your/dir | grep "# file:"

這將列出它們,並且 grep 僅保留檔案名稱。

答案2

sfindfind內建的bosh外殼,它只是:

sfind . -acl
bosh -c 'find . -acl'
-acl The primary evaluates as true if  the  file  has  addi-
     tional  ACLs defined.  On platforms that do not support
     ACLs or where sfind does not yet support ACLs, the pri-
     mary   always   evaluates  as  false.   Currently  only
     Solaris, Linux and FreeBSD is supported.

sfind和均bosh作為希利工具

得到類似的東西getfacl通常在 GNU 系統上找到的指令,建立在愛德華多的回答,我們需要解碼文件字段(其中使用表示形式和asgetfacl編碼一些字節值),如下所示:\ooo\\\

getfacl -Rs  . | perl -nle '
  if (/^# file: (.*)/) {
    print $1 =~ s{\\(\\|[0-7]{3})}{
      $1 eq "\\" ? "\\" : chr oct $1}ger
  }'

要對該文件清單執行某些操作,因為我們不能在此處使用find's -exec,您需要列印 NUL 分隔的清單:

getfacl -Rs  . | perl -nl0e '
  if (/^# file: (.*)/) {
    print $1 =~ s{\\(\\|[0-7]{3})}{
      $1 eq "\\" ? "\\" : chr oct $1}ger
  }'

因此,您可以使用(zsh)或(bash 4.4+)將其xargs -r0 some-command透過管道傳輸或儲存在陣列中。array=( ${(0)"$(cmd)"} )readarray -td '' < <(cmd)

相關內容