您的位置:首页 > 运维架构 > Linux

每天回顾linux命令(stat)

2017-11-13 11:11 483 查看
stat命令

stat命令用于显示文件的状态信息。

语法

stat (选项) (参数)

选项

-L:支持符号链接,当文件是链接文件时候,显示的是目标时间的stat

root@68fc0a9bc6dd:/home/wzm/testtail# stat aaa
File: 'aaa' -> 'redis.conf'
Size: 10              Blocks: 0          IO Block: 4096   symbolic link
Device: 70h/112d        Inode: 8398        Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2017-11-12 06:13:26.834836056 +0000
Modify: 2017-11-12 06:13:26.834836056 +0000
Change: 2017-11-12 06:13:26.834836056 +0000
Birth: -
root@68fc0a9bc6dd:/home/wzm/testtail# stat -L aaa
File: 'aaa'
Size: 57764           Blocks: 120        IO Block: 4096   regular file
Device: 70h/112d        Inode: 8384        Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2017-11-12 04:58:43.494831644 +0000
Modify: 2017-11-12 04:58:27.774885989 +0000
Change: 2017-11-12 04:58:27.774885989 +0000
Birth: -


-f:显示文件系统状态而非文件状态

root@68fc0a9bc6dd:/home/wzm/testtail# stat  aaa
File: 'aaa' -> 'redis.conf'
Size: 10              Blocks: 0          IO Block: 4096   symbolic link
Device: 70h/112d        Inode: 8398        Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2017-11-12 06:13:26.834836056 +0000
Modify: 2017-11-12 06:13:26.834836056 +0000
Change: 2017-11-12 06:13:26.834836056 +0000
Birth: -
root@68fc0a9bc6dd:/home/wzm/testtail# stat -f aaa
File: "aaa"
ID: 0        Namelen: 242     Type: aufs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 4686334    Free: 1567559    Available: 1319878
Inodes: Total: 2436448    Free: 2233036


-t:以简洁方式输出信息

root@68fc0a9bc6dd:/home/wzm/testtail# stat  aaa
File: 'aaa' -> 'redis.conf'
Size: 10              Blocks: 0          IO Block: 4096   symbolic link
Device: 70h/112d        Inode: 8398        Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2017-11-12 06:13:26.834836056 +0000
Modify: 2017-11-12 06:13:26.834836056 +0000
Change: 2017-11-12 06:13:26.834836056 +0000
Birth: -
root@68fc0a9bc6dd:/home/wzm/testtail# stat -t aaa
aaa 10 0 a1ff 0 0 70 8398 1 0 0 1510467206 1510467206 1510467206 0 4096


-c或者–format=格式:使用指定格式代替默认值,每用一次指定格式换一新行。

格式相应定定义如下:

%a   access rights in octal (note '#' and '0' printf flags)
%A   access rights in human readable form
%b   number of blocks allocated (see %B)
%B   the size in bytes of each block reported by %b
%C   SELinux security context string
%d   device number in decimal
%D   device number in hex
%f   raw mode in hex
%F   file type
%g   group ID of owner
%G   group name of owner
%h   number of hard links
%i   inode number
%m   mount point
%n   file name
%N   quoted file name with dereference if symbolic link
%o   optimal I/O transfer size hint
%s   total size, in bytes
%t   major device type in hex, for character/block device special files
%T   minor device type in hex, for character/block device special files
%u   user ID of owner
%U   user name of owner
%w   time of file birth, human-readable; - if unknown
%W   time of file birth, seconds since Epoch; 0 if unknown
%x   time of last access, human-readable
%X   time of last access, seconds since Epoch
%y   time of last data modification, human-readable
%Y   time of last data modification, seconds since Epoch
%z   time of last status change, human-readable
%Z   time of last status change, seconds since Epoch


Valid format sequences for file systems:

%a   free blocks available to non-superuser
%b   total data blocks in file system
%c   total file nodes in file system
%d   free file nodes in file system
%f   free blocks in file system
%i   file system ID in hex
%l   maximum length of filenames
%n   file name
%s   block size (for faster transfers)
%S   fundamental block size (for block counts)
%t   file
b5b6
system type in hex
%T   file system type in human readable form


eg:

root@68fc0a9bc6dd:/home/wzm/testtail# stat redis.conf -c %n
redis.conf
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: