linux命令stat,linux stat命令详解

linux stat命令是linux下的一个命令,那么它的基本用法是怎样的呢?下面由学习啦小编为大家整理了linux stat命令命令的相关知识,希望对大家有帮助。

linux stat命令功能说明

显示inode内容。

linux stat命令语法

stat [文件或目录]

补充说明

stat以文字的格式来显示inode的内容。

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

下面演示了如何对可执行文件“oracle”(位于 $ORACLE_HOME/bin 目录下)使用此命令。

# cd $ORACLE_HOME/bin

# stat oracle

File: `oracle'

Size: 93300148 Blocks:182424 IO Block:4096 Regular File

Device: 343h/835d Inode: 12009652 Links: 1

Access: (6751/-rwsr-s--x) Uid:( 500/ oracle) Gid:( 500/ dba)

Access: 2006-08-04 04:30:52.000000000 -0400

Modify: 2005-11-02 11:49:47.000000000 -0500

Change: 2005-11-02 11:55:24.000000000 -0500

注意使用该命令获得的信息:除了通常的文件大小(也可以使用 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。这是某个人开始使用数据库的时间。该文件的date.html' target='_blank'>修改时间是 2005-11-02 11:49:47(显示在“Modify:”的旁边)。最后,“Change:”旁边的时间戳显示文件状态更改的时间。

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

# stat -f oracle

File: "oracle"

ID: 0 Namelen:255 Type:ext2/ext3

Blocks: Total: 24033242 Free: 15419301 Available: 14198462 Size: 4096

Inodes: Total: 12222464 Free: 12093976

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

# stat -t oracle

oracle 93300148 182424 8de9 500 500 343 12009652 1 0 0 1154682061

1130950187 1130950524 4096

Everything in Unix is treated as files. This includes devices, directories and sockets — all of these are files. Stat command displays file or filesystem status as explained in this article.

File Stat – Display Information About File

For example, to find out more information about 101hacks.txt file, execute the stat command as shown below.

$ stat 101hacks.txt

File: `/home/sathiyamoorthy/101hacks.txt'

Size: 854 Blocks: 8 IO Block: 4096 regular file

Device: 801h/2049d Inode: 1058122 Links: 1

Access: (0600/-rw-------) Uid: ( 1000/ sathiya) Gid: ( 1000/ sathiya)

Access: 2009-06-28 19:29:57.000000000 +0530

Modify: 2009-06-28 19:29:57.000000000 +0530

Change: 2009-06-28 19:29:57.000000000 +0530

Details of Linux Stat Command Output

File: `/home/sathiyamoorthy/101hacks.txt’ – Absolute path name of the file.

Size: 854 – File size in bytes.

Blocks: 8 – Total number of blocks used by this file.

IO Block: 4096 – IO block size for this file.

regular file – Indicates the file type. This indicates that this is a regular file. Following are available file types.

regular file. ( ex: all normal files ).

directory. ( ex: directories ).

socket. ( ex: sockets ).

symbolic link. ( ex: symbolic links. )

block special file ( ex: hard disk ).

character special file. ( ex: terminal device file ).

Device: 801h/2049d – Device number in hex and device number in decimal

Inode: 1058122 – Inode number is a unique number for each file which is used for the internal maintenance by the file system.

Links: 1 – Number of links to the file

Access: (0600/-rw——-): Access specifier displayed in both octal and character format. Let us see explanation about both the format.

Uid: ( 1000/ sathiya) – File owner’s user id and user name are displayed.

Gid: ( 1000/ sathiya) – File owner’s group id and group name are displayed.

Access: 2009-06-28 19:29:57.000000000 +0530 – Last access time of the file.

Modify: 2009-06-28 19:29:57.000000000 +0530 – Last modification time of the file.

Change: 2009-06-28 19:29:57.000000000 +0530 – Last change time of the inode data of that file.

Dir Stat – Display Information About Directory

You can use the same command to display the information about a directory as shown below.

$ stat /home/ramesh

File: `/home/ramesh'

Size: 4096 Blocks: 8 IO Block: 4096 directory

Device: 803h/2051d Inode: 5521409 Links: 7

Access: (0755/drwxr-xr-x) Uid: ( 401/ramesh) Gid: ( 401/ramesh)

Access: 2009-01-01 12:17:42.000000000 -0800

Modify: 2009-01-01 12:07:33.000000000 -0800

Change: 2009-01-09 12:07:33.000000000 -0800

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值