![列出路径中的访问权限](https://linux22.com/image/131159/%E5%88%97%E5%87%BA%E8%B7%AF%E5%BE%84%E4%B8%AD%E7%9A%84%E8%AE%BF%E9%97%AE%E6%9D%83%E9%99%90.png)
有没有更好的方法(避免重复替换)来列出路径中的访问权限
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
答案1
一个小的 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 /