Book Image

CentOS System Administration Essentials

Book Image

CentOS System Administration Essentials

Overview of this book

Table of Contents (18 chapters)
CentOS System Administration Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Understanding the command stat


The CentOS command line is full of tools, and trying to learn them all is perhaps a lifetime's work. As with all tasks, reaching the finish line begins with the first step. Our first step will be to delve into the world of the /usr/bin/stat command. By using this command, we can query a file's metadata. A file in CentOS consists of:

  • A filename (hard link)

  • File metadata (inode)

  • Data

Using stat and the filename alone, we can view the complete inode metadata. This is demonstrated with the following group of commands:

$ cd #move to your home directory
$ ls > my_newfile #list the contents and redirect the output to the new file
$ stat my_newfile #display the inode metadata

The following screenshot displays the output of stat:

We can see that the complete metadata is displayed, but if we choose, we can display just elements of the metadata; for example, to display the file permissions in the octal format, run the following command:

$ stat -c%a my_newfile

To display...