Basic tutorial on using STAT command to display files in Linux

Source: Internet
Author: User
Tags file size readable valid

Usage: stat [options] ... File...

Displays the status of the file or file system.

-L,--dereference follow link

-F,--file-system displays file system state rather than file state

The-C--format= format replaces the default value with the specified output format, exchanging a new row for each specified format

The--printf= format is similar to--format, but it interprets the backslash escape character and does not use line breaks

The end of the output. If you still want to use wrapping, you can do so in the format

Add "n"

-T,--terse using concise format output

--HELP displays this help information and exits

--version display version information and exit

Valid sequence of file formats (--file-system not used):

%a octal Permissions

%A output permissions in a better readable manner

%b Count Allocated blocks (see%B)

%B 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 Primitive Mode

%F file type

Group ID of the%g file

%G group name of the file

%h Number of hard links

%i Inode Number

%m mount point

%n file name

%N if the object is a symbolic link, display a reference to another file name

%o I/O block size

%s total size, in bytes

%t hexadecimal main device type

%T Hexadecimal child device type

The owner ID of the%u file

%u file's owner username

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

%w the file creation time in seconds from the beginning of Unix, if unknown, displays "-"

%x Last access time

%x's last access time in seconds from the beginning of Unix

%y Last Modified Time

%Y last modified time in seconds from the beginning of Unix

%z Last Change time

%Z last change time in seconds from the beginning of Unix

Valid file system format sequence:

%a number of remaining blocks available to non-super users

Total block number of%b file system

Total number of file nodes in%c file system

%d number of idle file nodes in file system

Number of idle blocks in%f file system

%i hexadecimal file System ID

%I Maximum length of file names allowed

%n file name

%s block size (for fast transfer)

%s base block Size (for block count)

%t Hexadecimal type description

%T a better readable type description

Note: Your shell contains its own version of the stat program, which overwrites the corresponding

Version. Consult your shell documentation for the options it supports.

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

The following shows how to use this command for an 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:52.000000000-0400

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

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

Note the information obtained 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 that the file occupies. The usual Linux block size is 512 bytes, so a file size of 93,300,148 bytes will occupy (93300148/512=) 182226.85 blocks. Because the block is fully occupied, the file uses a number of blocks of integers. You can get the exact number of blocks without guessing.

You can also obtain the GID and UID of file ownership from the above output, and the octal representation of permissions (6751). If you want to restore the file to the same permissions that it now has, you can use chmod 6751 Oracle instead of explicitly spelling these permissions.

The most useful part of the above output is file access timestamp information. The output shows that the file was accessed 2006-08-04 04:30:52 (next to "Access:"), that is, August 4, 2006 4:30:52. This is when someone starts using the database. The file was modified 2005-11-02 11:49:47 (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 is displayed on one line:

The code is as follows:

# stat-t Oracle

Oracle 93300148 182424 8DE9 500 500 343 12009652 1 0 0 1154682061

1130950187 1130950524 4096

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.