ls 命令及其许多参数提供了一些非常有用的文件信息。另一个不太为人所熟知的命令 stat 提供了一些更为有用的信息。

 [root@Gin scripts]# man stat
STAT() User Commands STAT() NAME
stat - display file or file system status SYNOPSIS
stat [OPTION]... FILE... DESCRIPTION
Display file or file system status. -L, --dereference
follow links :
STAT() User Commands STAT() NAME
stat - display file or file system status SYNOPSIS
stat [OPTION]... FILE... DESCRIPTION
Display file or file system status. -L, --dereference
follow links -Z, --context
print the SELinux security context -f, --file-system
display file system status instead of file status -c --format=FORMAT
use the specified FORMAT instead of the default; output a newline
after each use of FORMAT --printf=FORMAT
like --format, but interpret backslash escapes, and do not output a
mandatory trailing newline. If you want a newline, include \n in
FORMAT. -t, --terse
print the information in terse form --help display this help and exit --version
output version information and exit The valid format sequences for files (without --file-system): %a Access rights in octal %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 %n File name %N Quoted file name with dereference if symbolic link %o I/O block size %s Total size, in bytes %t Major device type in hex %T Minor device type in hex %u User ID of owner %U User name of owner %x Time of last access %X Time of last access as seconds since Epoch %y Time of last modification %Y Time of last modification as seconds since Epoch %z Time of last change %Z Time of last change as 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 %C SELinux security context string %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 Type in hex %T Type in human readable form NOTE: your shell may have its own version of stat, which usually super-
sedes the version described here. Please refer to your shell’s documenta-
tion for details about the options it supports. AUTHOR
Written by Michael Meskes. REPORTING BUGS
Report stat bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
Report stat translation bugs to <http://translationproject.org/team/> COPYRIGHT
Copyright © Free Software Foundation, Inc. License GPLv3+: GNU GPL
version or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There
is NO WARRANTY, to the extent permitted by law. SEE ALSO
stat() The full documentation for stat is maintained as a Texinfo manual. If the
info and stat programs are properly installed at your site, the command info coreutils 'stat invocation' should give you access to the complete manual. GNU coreutils 8.4 October STAT()

man stat

下面演示了stat 不带参数显示的信息:

[root@Gin scripts]# stat date.txt
File: `date.txt'
Size: 40 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 261790 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-01-29 10:49:25.119790781 +0800
Modify: 2017-01-29 10:49:11.961790098 +0800
Change: 2017-01-29 10:49:11.961790098 +0800

注意使用该命令获得的信息:除了通常的文件大小(也可以使用 ls -l 命令获得)以外,您还获得了该文件占用的块数。通常的 Linux 块大小为 512 字节,因此一个大小为 93,300,148 字节的文件将占用 (93300148/512=) 182226.85 个块。由于块都是完整占用,因此该文件使用了一些整数个数的块。无需猜测就可以获得确切的块数。

  您还可以从以上输出中获得文件所有权的 GID 和 UID,以及权限的八进制表示形式 (6751)。如果要将文件恢复到它现在具有的相同权限,可以使用 chmod 6751 oracle,而不是显式拼写这些权限。

  以上输出最有用的部分是文件访问时间戳信息。该输出显示,该文件被访问的时间是 2006-08-04 04:30:52(显示在“Access:”的旁边),即 2006 年 8 月 4 日上午 4:30:52。这是某个人开始使用数据库的时间。该文件的修改时间是 2005-11-02 11:49:47(显示在“Modify:”的旁边)。最后,“Change:”旁边的时间戳显示文件状态更改的时间。

  stat 命令的修改符 -f 显示了有关文件系统(而非文件)的信息:

[root@Gin scripts]# stat -f date.txt
File: "date.txt"
ID: ff0d2532e41897c0 Namelen: 255 Type: ext2/ext3
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 1851748 Free: 1286127 Available: 1190396
Inodes: Total: 479552 Free: 409340

另一个选项 -t 显示了完全相同的信息,只不过是在一行中显示的:

[root@Gin scripts]# stat -t date.txt
date.txt 40 8 81a4 0 0 803 261790 1 0 0 1485658165 1485658151 1485658151 4096

这对 shell 脚本非常有用,在 shell 脚本中可以使用一个简单的 cut 命令获得值以进行进一步处理。

应用案例:

如何取得stat /poe命令后文件的权限对应的数字内容,如-rw-r--r--为644,要求使用命令取得644或0644这样的数字。

[root@Gin scripts]# stat date.txt
File: `date.txt'
Size: 40 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 261790 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-01-29 10:49:25.119790781 +0800
Modify: 2017-01-29 10:49:11.961790098 +0800
Change: 2017-01-29 10:49:11.961790098 +0800
[root@Gin scripts]# stat -c %a date.txt
644

linux命令总结之state命令的更多相关文章

  1. linux运维中的命令梳理(四)

    ----------管理命令---------- ps命令:查看进程 要对系统中进程进行监测控制,查看状态,内存,CPU的使用情况,使用命令:/bin/ps (1) ps :是显示瞬间进程的状态,并不 ...

  2. linux运维中的命令梳理(一)

    在linux日常运维中,我们平时会用到很多常规的操作命令. 下面对常用命令进行梳理: 命令行日常系快捷键(不分大小写)CTRL + A 移动光标到行首CTRL + E 移动光标到行末CTRL + U ...

  3. Linux 新手非常有用的命令

    http://www.cnblogs.com/felix-/p/4341773.html Linux 新手非常有用的命令 你打算从Windows换到Linux上来,还是你刚好换到Linux上来?哎哟! ...

  4. 监控Linux性能的18个命令行工具

    监控 Linux 性能的 18 个命令行工具 对于系统和网络管理员来说每天监控和调试Linux系统的性能问题是一项繁重的工作.在IT领域作为一名Linux系统的管理员工作5年后,我逐渐 认识到监控和保 ...

  5. 监控 Linux 性能的 18 个命令行工具

    http://www.oschina.net/translate/command-line-tools-to-monitor-linux-performance 1.Top-Linux进程监控 Lin ...

  6. linux ftp 安装及相关命令

    1.VSFTP简介 VSFTP是一个基于GPL发布的类Unix系统上使用的FTP服务器软件,它的全称是Very Secure FTP 从此名称可以看出来,编制者的初衷是代码的安全. 安全性是编写VSF ...

  7. linux中iptables配置文件及命令详解详解

    iptables配置文件 直接改iptables配置就可以了:vim /etc/sysconfig/iptables. 1.关闭所有的 INPUT FORWARD OUTPUT 只对某些端口开放. 下 ...

  8. 监控 Linux 性能的 18 个命令行工具[转]

    对于系统和网络管理员来说每天监控和调试Linux系统的性能问题是一项繁重的工作.在IT领域作为一名Linux系统的管理员工作5年后,我逐渐认识到监控和保持系统启动并运行是多么的不容易.基于此原因,我们 ...

  9. Linux基础 - 系统优化及常用命令

    目录 Linux基础系统优化及常用命令 Linux基础系统优化 网卡配置文件详解 ifup,ifdown命令 ifconfig命令 ifup,ifdown命令 ip命令 用户管理与文件权限篇 创建普通 ...

随机推荐

  1. 团队博客作业Week3 --- 项目选择&&需求疑问

    项目选择 经过团队内所有成员一致探讨,我们团队选择完善和改进之学霸系统的第二个子模块,即:网站内容结构定义和数据处理.具体的要求如下:(摘自Xueba系统项目需求) 网站内容结构定义和数据处理(Con ...

  2. Leetcode题库——11.盛最多水的容器

    @author: ZZQ @software: PyCharm @file: maxArea.py @time: 2018/10/11 21:47 说明:给定 n 个非负整数 a1,a2,...,an ...

  3. SpringMVC(一)-- springmvc的系统学习之配置方式

    资源:尚学堂  邹波 springmvc框架视频  一.springMVC 工作流程        页面请求---->控制器(Controller DispatcherServlet)----& ...

  4. java异常处理及自定义异常的使用

    1. 异常介绍 异常机制可以提高程序的健壮性和容错性. Throwable:Throwable是java语言所有错误或异常的超类. 有两个子类Error和Exception. 1.1 编译期异常 编译 ...

  5. Good Time 冲刺 六

    一.今日完成任务情况 第六天 日期:2018.6.19 王怡镔:今天完善了页面,对部分不足进行改进. 于鑫宇:对界面进行完善. 胡雅馨:今天完成前端页面,并改善后端,完善项目. 黄 鹤:做完最后的打卡 ...

  6. CANOpen的几种操作以及数据

    其实3年前在21ic就准备做这篇文章了,那时,CANOpen也只是刚刚在国内推广,所以几乎没有项目用到.现在有了实际的项目,完全确认了以前移植和测试的代码,所以列举一些CANOpen的底层操作以及数据 ...

  7. 关于js基本类型与引用类型(堆内存、栈内存的理解)

    js 基本类型与引用类型的区别 ECMAScirpt 变量有两种不同的数据类型:基本类型,引用类型.也有其他的叫法,比如原始类型和对象类型,拥有方法的类型和不能拥有方法的类型,还可以分为可变类型和不可 ...

  8. maven下载、安装、卸载以及MyEclipse配置maven

    maven下载 官网下载:http://maven.apache.org/download.cgi 点击链接为官网下载页面,翻到下图所示位置,点击红框选项即可下载 maven安装 1.解压       ...

  9. IE 低版本 透明度

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. PGM学习之四 Factor,Reasoning

    通过上一篇文章的介绍,我们已经基本了解了:Factor是组成PGM模型的基本要素:Factor之间的运算和推理是构建高维复杂PGM模型的基础.那么接下来,我们将重点理解,Factor之间的推理(Rea ...