Linux查看文件属性的几种方法

Table of Contents

    Linux下查看文件属性有多种方法,且这些方法中偏向不同,具体如下:

 

1  ls

    ls -a 查看所有文件

    ls -l 查看详细的属性

     [pc@li1209-91 ~]$ ls -a ; ls -l
. .. bak .bash_history .bash_logout .bash_profile .bashrc .lesshst .lftp lujiaz .ssh .viminfo wordpress wp-ueditor
total 16
drwxrwxr-x 3 pc pc 4096 Sep 10 12:37 bak
drwxr-xr-x 4 nginx root 4096 Jul 7 20:30 lujiaz
drwxr-xr-x 5 pc pc 4096 Sep 8 01:41 wordpress
drwxr-xr-x 3 root root 4096 Sep 11 11:57 wp-ueditor

2  lsattr

    查看文件的扩展属性,

    如果文件被 chattr +i   添加了写保护,

    用lsattr可以看到添加的属性

[pc@li1209-91 ~]$ chattr +i test ; lsattr test
chattr: Operation not permitted while setting flags on test
-------------e- test

3  file

查看文件的类型

[pc@li1209-91 ~]$ file test
test: empty
[pc@li1209-91 ~]$ file /bin/bash
/bin/bash: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
[pc@li1209-91 ~]$ file /etc/init.d/mysqld
/etc/init.d/mysqld: POSIX shell script text executable

4  stat

    查看文件的状态

[pc@li1209-91 ~]$ stat /bin/bash
File: `/bin/bash'
Size: 904872 Blocks: 1768 IO Block: 4096 regular file
Device: 800h/2048d Inode: 8633 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-10-16 21:56:16.000000000 +0800
Modify: 2014-10-16 21:56:16.000000000 +0800
Change: 2015-06-27 13:47:59.661899649 +0800

[pc@li1209-91 ~]$ stat /etc/init.d/mysqld
File: `/etc/init.d/mysqld'
Size: 10880 Blocks: 24 IO Block: 4096 regular file
Device: 800h/2048d Inode: 868388 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2016-03-13 21:37:29.528864937 +0800
Modify: 2016-03-13 21:37:29.528864937 +0800
Change: 2016-03-13 21:37:50.231529030 +0800
[pc@li1209-91 ~]$

[pc@li1209-91 ~]$ stat test
File: `test'
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 800h/2048d Inode: 155987 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 500/ pc) Gid: ( 501/ pc)
Access: 2016-09-11 20:01:34.781427826 +0800
Modify: 2016-09-11 20:01:34.781427826 +0800
Change: 2016-09-11 20:01:34.781427826 +0800

5  getfacl

查看文件权限

[pc@li1209-91 ~]$ getfacl test
# file: test
# owner: pc
# group: pc
user::rw-
user:root:r-x
group::rw-
mask::rwx
other::r--[pc@li1209-91 ~]$

[pc@li1209-91 ~]$ getfacl /bin/bash
getfacl: Removing leading '/' from absolute path names
# file: bin/bash
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

[pc@li1209-91 ~]$ getfacl /etc/init.d/mysqld
getfacl: Removing leading '/' from absolute path names
# file: etc/init.d/mysqld
# owner: root
# group: root
user::rwx
group::r-x
other::r-x