Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Tutorials on the use of stat command display files in Linux

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "Linux stat command display file use tutorial", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and study the "Linux stat command display file use tutorial" it!

Usage: stat [option]. A document.

Displays the status of the file or file system.

-L,-- dereference follow the link

-f,-- file-system displays the file system status instead of the file status

-c-- the format= format uses the specified output format instead of the default value, replacing a new line each time with the specified format

-- printf= format is similar to-- format, but interprets backslash escape characters and does not use line breaks

The end of the output. If you still want to use line breaks, you can use them in the format

Add "\ n"

-t,-- terse outputs in a concise format

-- help displays this help and exits

-- version displays version information and exits

Valid file format sequence (do not use-- file-system):

An Octal permissions

% An outputs permissions in a readable manner

% b calculates the number of allocated blocks (see% B)

% B outputs the size of each block reported by% b in bytes

% C SELinux Security Environment string

D decimal device number

% D hexadecimal device number

% f hexadecimal original mode

% F File Type

Group ID of g file

The group name of the G file

% h number of hard links

% I Inode number

% m mount point

% n File name

% N if the object is a symbolic link, display the other file names referenced

% o Istroke O block size

% s total size in bytes

% t hexadecimal master device type

% T hexadecimal subdevice type

Owner ID of u file

Owner user name of% U file

% w file creation time, display "-" if unknown

% W file creation time in seconds from the first year of UNIX, showing "-" if unknown

% x Last visit time

% X Last visit time in seconds from the first year of UNIX

% y Last modified time

% Y Last modified time in seconds from the first year of UNIX

Z Last change time

% Z Last change time in seconds since the first year of UNIX

Valid file system format sequence:

% a number of remaining blocks available to non-superusers

B total number of blocks for the file system

% c Total number of file nodes in the file system

D number of free file nodes in the file system

% f number of free blocks in the file system

% I hexadecimal file system ID

Maximum length of file name allowed by% I

% n File name

% s block size (for fast transfer)

% S basic block size (for block counting)

% t hexadecimal type description

Type description with good readability of% T

Note: your shell contains your own version of the stat program, which will cover the corresponding ones mentioned here

Version. Please refer to your shell documentation for the options it supports.

The ls command and many of its arguments provide some very useful file information. Another lesser-known command, stat, provides some more useful information.

The following demonstrates how to use this command on the executable file "oracle" (located in the $ORACLE_HOME/bin directory).

The code is as follows:

# 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 Vera 52.000000000-0400

Modify: 2005-11-02 11 purl 4949 purl 47.000000000-0500

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

Note the information you get using this command: in addition to the usual file size (which can also be obtained using the ls-l command), you also get the number of blocks occupied by the file. The typical Linux block size is 512 bytes, so a file with a size of 93300148 bytes will occupy 182226.85 blocks (93300148Universe 512 =). Because the blocks are fully occupied, the file uses a number of integer blocks. The exact number of blocks can be obtained without guessing.

You can also get the GID and UID of file ownership from the above output, as well as the octal representation of permissions (6751). If you want to restore a file to the same permissions it now has, you can use chmod 6751 oracle instead of explicitly spelling those permissions.

The most useful part of the above output is the file access timestamp information. The output shows that the file was accessed at 04:30:52 on 2006-08-04 (displayed next to "Access:"), that is, 4:30:52 on August 4, 2006. This is the time when someone starts using the database. The file was modified at 11:49:47, 2005-11-02 (shown next to "Modify:"). Finally, the timestamp next to "Change:" shows when the state of the file changed.

The modifier-f of the stat command displays information about the file system, not the file:

The code is as follows:

# 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

The other option,-t, displays exactly the same information, but on one line:

The code is as follows:

# stat-t oracle

Oracle 93300148 182424 8de9 500 500 343 12009652 1 00 1154682061

1130950187 1130950524 4096

This is very useful for shell scripts, where you can use a simple cut command to get a value for further processing.

Thank you for your reading, these are the contents of the tutorial on the use of stat command display files in Linux. After the study of this article, I believe you have a deeper understanding of the use of stat command display files in Linux, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report