{"id":12421,"date":"2019-03-26T23:33:18","date_gmt":"2019-03-26T23:33:18","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12421"},"modified":"2019-03-26T23:33:18","modified_gmt":"2019-03-26T23:33:18","slug":"5-stat-command-examples-for-linux-newbies","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/5-stat-command-examples-for-linux-newbies\/","title":{"rendered":"5 \u2018stat\u2019 Command Examples for Linux Newbies"},"content":{"rendered":"<p><strong>stat command<\/strong>\u00a0is a useful utility for viewing file or file system status. It retrieves information such as file type; access rights in octal and human-readable;\u00a0<a href=\"https:\/\/www.tecmint.com\/selinux-essentials-and-control-filesystem-access\/\" target=\"_blank\" rel=\"noopener\">SELinux security context string<\/a>; time of file birth, last access,\u00a0<a href=\"https:\/\/www.tecmint.com\/find-recent-modified-files-in-linux\/\" target=\"_blank\" rel=\"noopener\">last data modification<\/a>, last status change in both human-readable and in seconds since Epoch, and much more.<\/p>\n<p>It has an option to specify a custom format instead of the default, for displaying information. In this guide, we will look at five stat command examples for Linux newbies.<\/p>\n<h3>Check Linux File Status<\/h3>\n<p><strong>1.<\/strong>\u00a0The easiest way to use\u00a0<strong>stat<\/strong>\u00a0is to provide it a file as an argument. The following command will display the size, blocks, IO blocks, file type, inode value, number of links and much more information about the file \/var\/log\/syslog, as shown in the screenshot:<\/p>\n<pre><strong>$ stat \/var\/log\/syslog<\/strong>\r\n\r\nFile: '\/var\/log\/syslog'\r\n  Size: 26572     \tBlocks: 56         IO Block: 4096   regular file\r\nDevice: 80ah\/2058d\tInode: 8129076     Links: 1\r\nAccess: (0640\/-rw-r-----)  Uid: (  104\/  syslog)   Gid: (    4\/     adm)\r\nAccess: 2018-04-06 09:42:10.987615337 +0530\r\nModify: 2018-04-06 11:09:29.756650149 +0530\r\nChange: 2018-04-06 11:09:29.756650149 +0530\r\n Birth: -\r\n<\/pre>\n<h3>Check File System Status<\/h3>\n<p><strong>2.<\/strong>\u00a0In the previous example, stat command treated the input file as a normal file, however, to display file system status instead of file status, use the\u00a0<code>-f<\/code>\u00a0option.<\/p>\n<pre><strong>$ stat -f \/var\/log\/syslog<\/strong>\r\n\r\nFile: \"\/var\/log\/syslog\"\r\n    ID: ce97e63d2201c974 Namelen: 255     Type: ext2\/ext3\r\nBlock size: 4096       Fundamental block size: 4096\r\nBlocks: Total: 84769790   Free: 16012830   Available: 11700997\r\nInodes: Total: 21544960   Free: 20995459\r\n<\/pre>\n<p><center>You can also provide a directory\/filesystem as an argument as shown.<\/center><\/p>\n<pre><strong>$ stat -f \/<\/strong>\r\n\r\nFile: \"\/\"\r\n    ID: ce97e63d2201c974 Namelen: 255     Type: ext2\/ext3\r\nBlock size: 4096       Fundamental block size: 4096\r\nBlocks: Total: 84769790   Free: 16056471   Available: 11744638\r\nInodes: Total: 21544960   Free: 21005263\r\n<\/pre>\n<h3>Enable Following of Symbolic Links<\/h3>\n<p><strong>3.<\/strong>\u00a0Since Linux supports links (<strong>symbolic<\/strong>\u00a0and\u00a0<strong>hard links<\/strong>), certain files may have one or more links, or they could even exist in a filesystem.<\/p>\n<p>To enable stat to follow links, use the\u00a0<code>-L<\/code>\u00a0flag as shown.<\/p>\n<pre><strong>$ stat -L \/<\/strong>\r\n\r\n File: '\/'\r\n  Size: 4096      \tBlocks: 8          IO Block: 4096   directory\r\nDevice: 80ah\/2058d\tInode: 2           <strong>Links: 25<\/strong>\r\nAccess: (0755\/drwxr-xr-x)  Uid: (    0\/    root)   Gid: (    0\/    root)\r\nAccess: 2018-04-09 10:55:55.119150525 +0530\r\nModify: 2018-02-20 11:15:54.462893167 +0530\r\nChange: 2018-02-20 11:15:54.462893167 +0530\r\n Birth: -<\/pre>\n<h3>Use a Custom Format To Display Information<\/h3>\n<p><strong>4.<\/strong>\u00a0<strong>stat<\/strong>\u00a0also allows you to use a particular or custom format instead of the default. The\u00a0<code>-c<\/code>\u00a0flag is used to specify the format used, it prints a newline after each use of format sequence.<\/p>\n<p>Alternatively, you can use the\u00a0<code>--printf<\/code>\u00a0option which enables interpreting of backslash escapes sequences and turns off printing of a trailing newline. You need to use\u00a0<code>\\n<\/code>\u00a0in the format to print a new line, for example.<\/p>\n<pre># stat --printf='%U\\n%G\\n%C\\n%z\\n' \/var\/log\/secure\r\n<\/pre>\n<p>Meaning of the format sequences for files used in above example:<\/p>\n<ul>\n<li><strong>%U<\/strong>\u00a0\u2013 user name of owner<\/li>\n<li><strong>%G<\/strong>\u00a0\u2013 group name of owner<\/li>\n<li><strong>%C<\/strong>\u00a0\u2013 SELinux security context string<\/li>\n<li><strong>%z<\/strong>\u00a0\u2013 time of last status change, human-readable<\/li>\n<\/ul>\n<p><strong>5.<\/strong>\u00a0Here is an example which shows using of accepted format sequences for file systems.<\/p>\n<pre>$ stat --printf='%n\\n%a\\n%b\\n' \/\r\n<\/pre>\n<p>Meaning of the format sequences used in the above command.<\/p>\n<ul>\n<li><strong>%n<\/strong>\u00a0\u2013 shows the file name<\/li>\n<li><strong>%a<\/strong>\u00a0\u2013 print free blocks available to non-superuser<\/li>\n<li><strong>%b<\/strong>\u00a0\u2013 outputs total data blocks in file system<\/li>\n<\/ul>\n<h3>Print Information in Terse Form<\/h3>\n<p><strong>6.<\/strong>\u00a0The\u00a0<code>-t<\/code>\u00a0option can be used to print the information in terse form.<\/p>\n<pre><strong>$ stat -t \/var\/log\/syslog<\/strong>\r\n\r\n\/var\/log\/syslog 12760 32 81a0 104 4 80a 8129076 1 0 0 1523251873 1523256421 1523256421 0 4096\r\n<\/pre>\n<p>As a last note, your shell may have its own version of stat, please refer to your shell\u2019s documentation for details about the options it supports. To see all accepted output format sequences, refer to the stat man page.<\/p>\n<pre>$ man stat \r\n<\/pre>\n<p>In this article, we have explained five stat command examples for Linux newbies. Use the feedback form below to ask any questions.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/linux-stat-command-examples\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>stat command\u00a0is a useful utility for viewing file or file system status. It retrieves information such as file type; access rights in octal and human-readable;\u00a0SELinux security context string; time of file birth, last access,\u00a0last data modification, last status change in both human-readable and in seconds since Epoch, and much more. It has an option to &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/5-stat-command-examples-for-linux-newbies\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;5 \u2018stat\u2019 Command Examples for Linux Newbies&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12421","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12421"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12421\/revisions"}],"predecessor-version":[{"id":12422,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12421\/revisions\/12422"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}