Linux

列出路徑中的訪問權限

  • April 10, 2018

有沒有更好的方法(避免重複替換)在路徑中列出訪問權限

echo "/asdf/asd/asdas/asdasd/asdasd/asdwer" | sed -Ee 's#((.*)/.*)#\1\n\2#' \
-e 's#((.*)/.*)#\1\n\2#' -e 's#((.*)/.*)#\1\n\2#' -e 's#((.*)/.*)#\1\n\2#' -e 's#((.*)/.*)#\1\n\2#' -e 's#((.*)/.*)#\1\n\2#' -e 's#((.*)/.*)#\1\n\2#' -e 's#((.*)/.*)#\1\n\2#' -e 's#((.*)/.*)#\1\n\2#' -e 's#((.*)/.*)#\1\n\2#' \
-e 's#((.*)/.*)#\1\n\2#' | sort -u | xargs ls -dl

一個小shell循環就可以做到:

p=/var/log/messages
while [ $p != "/" ]; do ls -ld "$p"; p=$(dirname "$p"); done; ls -ld "$p"

樣本輸出:

-rw-------.  1 root root 241859 Apr 10 09:23 /var/log/messages
drwxr-xr-x. 14 root root   4096 Apr 10 03:32 /var/log
drwxr-xr-x. 26 root root   4096 Dec 13 16:10 /var
dr-xr-xr-x. 30 root root   4096 Dec 13 16:10 /

引用自:https://unix.stackexchange.com/questions/436760