如何通过终端显示文件属性?


58

什么是显示文件信息(或属性)的命令行,例如GNOME 中的GUI方法“ 显示属性”

显示属性GNOME

我知道那ls -l显示属性;但是如何显示相同的信息?

例如,代替

rw-rw-r--

我们有这样的GUI渲染:

abdennour@estifeda: $wishedCmd myFile
 ..... 
  Permissions : 
    Owner Access: Read & write 
    Group Access :Read & Write 
    Others Access: Read only
   .....

权限对话框的屏幕截图


9
stat呢 这将为您提供有关选定文件或文件夹的大量信息;见man stat

Answers:


15

就像是

#!/bin/bash
print_perm() {
  case "$1" in
    0) printf "NO PERMISSIONS";;
    1) printf "Execute only";;
    2) printf "Write only";;
    3) printf "Write & execute";;
    4) printf "Read only";;
    5) printf "Read & execute";;
    6) printf "Read & write";;
    7) printf "Read & write & execute";;
  esac
}

[[ ! -e $1 ]] &&  echo "$0 <file or dir>" 2>&1 && exit 1

perm=$(stat -c%a "$1")
user=${perm:0:1}
group=${perm:1:1}
global=${perm:2:1}

echo "Permissions :"
printf "\tOwner Access: $(print_perm $user)\n"
printf "\tGroup Access: $(print_perm $group)\n"
printf "\tOthers Access: $(print_perm $global)\n"

输出量

# rwxr-x--- foo*
> ./abovescript foo
Permissions :
    Owner Access: Read & write & execute
    Group Access: Read & execute
    Others Access: NO PERMISSIONS

91

使用stat命令了解文件的详细信息。如果文件名为file_name,请使用

stat file_name

26

没有为此专用的命令。对于时间,大小和访问权限等元信息,请使用

ls -l path-to-file

您可能也对它是哪种文件感兴趣,file path-to-file将对此有所帮助。



6
ls -lh filename

用于人类可读的版本


这使文件大小“可读”。您将获得32K而不是31900。但是对于访问权限没有帮助。但无论如何还是有帮助的;-)
Tobias Gaertner



By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.