Linux命令(98)之stat

简介: Linux命令(98)之stat

linux命令之rmdir

1.stat介绍
linux命令stat用于显示文件(linux中一切皆文件)的状态信息

2.stat用法
stat [参数] file

stat常用参数
参数 说明
-f 查看文件所在文件系统状态信息
-c 按照在指定格式输出文件状态信息(指定格式如下)
-c文件有效格式符说明

格式符 说明
%a 八进制中的访问权限(644显示)
%A 人类可读形式的访问权(rwx显示)
%g 所有者的组ID
%G 所有者的组名称
%n 文件名
%u 所有者的用户ID
%U 所有者的用户名
3.实例
3.1.查看命令stat帮助
命令:

man stat

OR

stat --h

stat --help

[root@centos79-3 ~]# stat --help
Usage: stat [OPTION]... FILE...
Display file or file system status.

Mandatory arguments to long options are mandatory for short options too.
-L, --dereference follow links
-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
%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 modification, human-readable
%Y time of last modification, seconds since Epoch
%z time of last change, human-readable
%Z time of last 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 system type in hex
%T file system type in human readable form

NOTE: your shell may have its own version of stat, which usually supersedes
the version described here. Please refer to your shell's documentation
for details about the options it supports.
GNU coreutils online help: http://www.gnu.org/software/coreutils/
For complete documentation, run: info coreutils 'stat invocation'
[root@centos79-3 ~]#
3.2.查看文件状态信息
命令:

stat a.txt

[root@centos79-3 ~]# stat a.txt
File: ‘a.txt’
Size: 27 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 101365672 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2023-09-23 16:19:28.873029340 +0800
Modify: 2023-09-18 15:51:53.460207797 +0800
Change: 2023-09-18 15:51:53.460207797 +0800
Birth: -
[root@centos79-3 ~]#
文件状态信息 说明
File 显示文件名
Size 显示文件大小
Blocks 文件使用的数据块总数
IO Block IO块大小
regular file 文件类型(常规文件)
Device 设备编号
Inode Inode号
Links 链接数
Access 文件的权限
Gid、Uid 文件所有权的Gid和Uid
access time 最后存取时间(ls -lu filename),表示最后一次访问(仅仅是访问,没有改动)文件的时间
modify time 最后修改时间(ls -l filename ),表示最后一次修改文件的时间
change time 最后更改时间(ls -lc filename ),表示最后一次对文件属性改变的时间,包括权限,大小,属性等等
Birth time 文件创建时间,crtime,不过据查此属性linux已废弃,目前状态显示结果均为-
3.3.查看文件的权限
命令:

stat -c %a

stat -c %A

[root@centos79-3 ~]# stat -c %a a.txt
644
[root@centos79-3 ~]# stat -c %A a.txt
-rw-r--r--
[root@centos79-3 ~]#
3.4.查看文件所有者的用户ID
命令:

stat -c %u a.txt

[root@centos79-3 ~]# stat -c %u a.txt
0
3.5.查看文件所有者的用户名
命令:

stat -c %U a.txt

[root@centos79-3 ~]# stat -c %U a.txt
root
[root@centos79-3 ~]#
3.6.查看文件所有者的组ID
命令:

stat -c %g a.txt

[root@centos79-3 ~]# stat -c %g a.txt
0
3.7.查看文件所有者的组名
命令:

stat -c %G a.txt

[root@centos79-3 ~]# stat -c %G a.txt
root
[root@centos79-3 ~]#
3.8.查看文件的文件名称
命令:

stat -c %n a.txt

[root@centos79-3 ~]# stat -c %n a.txt
a.txt
[root@centos79-3 ~]#
3.9.查看命令stat的版本信息
命令:

stat --version

[root@centos79-3 ~]# stat --version
stat (GNU coreutils) 8.22
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 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.

Written by Michael Meskes.

————————————————
版权声明:本文为CSDN博主「小黑要上天」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/z19861216/article/details/133210774

目录
相关文章
|
2月前
|
Linux 应用服务中间件 Shell
二、Linux文本处理与文件操作核心命令
熟悉了Linux的基本“行走”后,就该拿起真正的“工具”干活了。用grep这个“放大镜”在文件里搜索内容,用find这个“探测器”在系统中寻找文件,再用tar把东西打包带走。最关键的是要学会使用管道符|,它像一条流水线,能把这些命令串联起来,让简单工具组合出强大的功能,比如 ps -ef | grep 'nginx' 就能快速找出nginx进程。
309 2
二、Linux文本处理与文件操作核心命令
|
2月前
|
Linux
linux命令—stat
`stat` 是 Linux 系统中用于查看文件或文件系统详细状态信息的命令。相比 `ls -l`,它提供更全面的信息,包括文件大小、权限、所有者、时间戳(最后访问、修改、状态变更时间)、inode 号、设备信息等。其常用选项包括 `-f` 查看文件系统状态、`-t` 以简洁格式输出、`-L` 跟踪符号链接,以及 `-c` 或 `--format` 自定义输出格式。通过这些选项,用户可以灵活获取所需信息,适用于系统调试、权限检查、磁盘管理等场景。
239 137
|
2月前
|
安全 Ubuntu Unix
一、初识 Linux 与基本命令
玩转Linux命令行,就像探索一座新城市。首先要熟悉它的“地图”,也就是/根目录下/etc(放配置)、/home(住家)这些核心区域。然后掌握几个“生存口令”:用ls看周围,cd去别处,mkdir建新房,cp/mv搬东西,再用cat或tail看文件内容。最后,别忘了随时按Tab键,它能帮你自动补全命令和路径,是提高效率的第一神器。
558 56
|
22天前
|
存储 安全 Linux
Linux卡在emergency mode怎么办?xfs_repair 命令轻松解决
Linux虚拟机遇紧急模式?别慌!多因磁盘挂载失败。本文教你通过日志定位问题,用`xfs_repair`等工具修复文件系统,三步快速恢复。掌握查日志、修磁盘、验重启,轻松应对紧急模式,保障系统稳定运行。
192 2
|
2月前
|
缓存 监控 Linux
Linux内存问题排查命令详解
Linux服务器卡顿?可能是内存问题。掌握free、vmstat、sar三大命令,快速排查内存使用情况。free查看实时内存,vmstat诊断系统整体性能瓶颈,sar实现长期监控,三者结合,高效定位并解决内存问题。
88 0
Linux内存问题排查命令详解
|
2月前
|
Unix Linux 程序员
Linux文本搜索工具grep命令使用指南
以上就是对Linux环境下强大工具 `grep` 的基础到进阶功能介绍。它不仅能够执行简单文字查询任务还能够处理复杂文字处理任务,并且支持强大而灵活地正则表达规范来增加查询精度与效率。无论您是程序员、数据分析师还是系统管理员,在日常工作中熟练运用该命令都将极大提升您处理和分析数据效率。
161 16
|
3月前
|
Linux 网络安全 开发工具
技术栈:这50条最常用的 Linux 命令你一定要会!
建议多在终端中实践,遇到不懂的命令就用 man 或 --help 了解详情!
461 0
|
3月前
|
安全 Linux Shell
Linux系统中sudo命令的高效运用技巧。
用户可以通过sudo -l来列出自己目前可执行的命令列表,这有助于用户了解自己的权限范围。
139 0
|
3月前
|
监控 Linux Shell
linux命令
常用 Linux 命令汇总
|
4月前
|
Linux C++
每天一个linux命令(8):cp 命令
cp 命令是 Linux 中用于复制文件或目录的命令。它的名字来源于英文单词 copy。这个命令非常常用,特别是在需要备份文件或创建文件副本时。
183 0
下一篇
开通oss服务