
如何取得檔案的八進位權限?
/tmp$ ls -al myfile
-rw-r--r-- 1 wim wheel 0B Oct 20 22:31 myfile
/tmp$ the_command myfile
644
嘗試了我在其他答案中找到的建議,但它不起作用:
/tmp$ stat -c "%a %n" myfile
stat: illegal option -- c
usage: stat [-FlLnqrsx] [-f format] [-t timefmt] [file ...]
答案1
獲得的新資訊(或更短):stat -f '%A' <filename>
您也可以用於*
所有文件和資料夾。如果您需要更好的格式,您可以使用
stat -f '%A %N' <filename>
它將顯示八進制權限和檔案名稱。
信用:
https://askubuntu.com/a/152003- 檢查此答案的第一則評論
http://geeklog.adamwilson.info/article/58/getting-file-permissions-in-octal-on-OS-X
編輯新增:要檢查結果,請嘗試執行stat -f "%Sp %OLp" <filename>
,這將為您提供 --rwxrwxrwx 樣式 + 八進位版本