How to check permissions of a specific directory?

后端 未结 10 466
无人共我
无人共我 2021-01-29 17:32

I know that using ls -l \"directory/directory/filename\" tells me the permissions of a file. How do I do the same on a directory?

I could obviously use

10条回答
  •  离开以前
    2021-01-29 17:56

    In GNU/Linux, try to use ls, namei, getfacl, stat.

    For Dir

    [flying@lempstacker ~]$ ls -ldh /tmp
    drwxrwxrwt. 23 root root 4.0K Nov  8 15:41 /tmp
    [flying@lempstacker ~]$ namei -l /tmp
    f: /tmp
    dr-xr-xr-x root root /
    drwxrwxrwt root root tmp
    [flying@lempstacker ~]$ getfacl /tmp
    getfacl: Removing leading '/' from absolute path names
    # file: tmp
    # owner: root
    # group: root
    # flags: --t
    user::rwx
    group::rwx
    other::rwx
    
    [flying@lempstacker ~]$ 
    

    or

    [flying@lempstacker ~]$ stat -c "%a" /tmp
    1777
    [flying@lempstacker ~]$ stat -c "%n %a" /tmp
    /tmp 1777
    [flying@lempstacker ~]$ stat -c "%A" /tmp
    drwxrwxrwt
    [flying@lempstacker ~]$ stat -c "%n %A" /tmp
    /tmp drwxrwxrwt
    [flying@lempstacker ~]$
    

    For file

    [flying@lempstacker ~]$ ls -lh /tmp/anaconda.log
    -rw-r--r-- 1 root root 0 Nov  8 08:31 /tmp/anaconda.log
    [flying@lempstacker ~]$ namei -l /tmp/anaconda.log
    f: /tmp/anaconda.log
    dr-xr-xr-x root root /
    drwxrwxrwt root root tmp
    -rw-r--r-- root root anaconda.log
    [flying@lempstacker ~]$ getfacl /tmp/anaconda.log
    getfacl: Removing leading '/' from absolute path names
    # file: tmp/anaconda.log
    # owner: root
    # group: root
    user::rw-
    group::r--
    other::r--
    
    [flying@lempstacker ~]$
    

    or

    [flying@lempstacker ~]$ stat -c "%a" /tmp/anaconda.log
    644
    [flying@lempstacker ~]$ stat -c "%n %a" /tmp/anaconda.log
    /tmp/anaconda.log 644
    [flying@lempstacker ~]$ stat -c "%A" /tmp/anaconda.log
    -rw-r--r--
    [flying@lempstacker ~]$ stat -c "%n %A" /tmp/anaconda.log
    /tmp/anaconda.log -rw-r--r--
    [flying@lempstacker ~]$
    

提交回复
热议问题