linux 中如何获取文件或文件夹的权限呢?
ls -ld /home/ |awk '{print $1}'|sed 's/^[a-zA-Z-]//'
rwxr-xr-x
[root@localhost array_study]# echo "obase=8;ibase=2;`ls -ld /home/ |awk '{print $1}'|sed 's/^[a-zA-Z-]//'|tr 'x|r|w' '1'|tr '-' '0'`"|bc
755
也可以封装成为一个函数:
脚本名:power01.sh
内容:
- #!/bin/sh
- power()
- {
- file_name="$1"
- $command_l
- if [ -d "$file_name" ];then
- command_l="ls -ld"
- else
- command_l="ls -l"
- fi
- echo "obase=8;ibase=2;`$command_l "$file_name" |awk '{print $1}'|sed 's/^[a-zA-Z-]//'|tr 'x|r|w' '1'|tr '-' '0'`"|bc
- }
- power "$1"
[root@localhost power_study]# sh power01.sh /home/whuang/
700
[root@localhost power_study]# ll -d /home/whuang/
drwx------ 53 whuang whuang 4096 11-29 15:22 /home/whuang/