STAT Function showing ALL info, stat options, and descriptions

statt(){ C=c;stat --h|sed '/Th/,/NO/!d;/%/!d'|while read l;do p=${l/% */};[ $p == %Z ]&&C=fc&&echo ^FS:^;echo "`stat -$C $p \"$1\"` ^$p^${l#%* }";done|column -ts^; }
This shows every bit of information that stat can get for any file, dir, fifo, etc. It's great because it also shows the format and explains it for each format option. If you just want stat help, create this handy alias 'stath' to display all format options with explanations. alias stath="stat --h|sed '/Th/,/NO/!d;/%/!d'" To display on 2 lines: ( F=/etc/screenrc N=c IFS=$'\n'; for L in $(sed 's/%Z./%Z\n/'<<<`stat --h|sed -n '/^ *%/s/^ *%\(.\).*$/\1:%\1/p'`); do G=$(echo "stat -$N '$L' \"$F\""); eval $G; N=fc;done; ) For a similarly powerful stat-like function optimized for pretty output (and can sort by any field), check out the "lll" function From my .bash_profile ->
Sample Output
[275:254 0:302] [ +6] /etc
(2:32)$ statt screenrc
644                    %a Access rights in octal
-rw-r--r--             %A Access rights in human readable form
40                     %b Number of blocks allocated (see %B)
512                    %B The size in bytes of each block reported by %b
86                     %d Device number in decimal
56                     %D Device number in hex
81a4                   %f Raw mode in hex
regular file           %F File type
0                      %g Group ID of owner
root                   %G Group name of owner
1                      %h Number of hard links
80002387               %i Inode number
/etc/screenrc          %n File name
`/etc/screenrc'        %N Quoted file name with dereference if symbolic link
4096                   %o I/O block size
20102                  %s Total size, in bytes
0                      %t Major device type in hex
0                      %T Minor device type in hex
0                      %u User ID of owner
root                   %U User name of owner
2010-06-11 14:23:28    %x Time of last access
1276280608             %X Time of last access as seconds since Epoch
2010-06-11 14:23:28    %y Time of last modification
1276280608             %Y Time of last modification as seconds since Epoch
2010-06-11 16:42:43    %z Time of last change
Z                      %Z Time of last change as seconds since Epoch
12190296               %a Free blocks available to non-superuser
20971520               %b Total data blocks in file system
5242880                %c Total file nodes in file system
4540105                %d Free file nodes in file system
12190296               %f Free blocks in file system
0                      %i File System ID in hex
255                    %l Maximum length of filenames
/etc/screenrc          %n File name
4096                   %s Block size (for faster transfers)
4096                   %S Fundamental block size (for block counts)
565a4653               %t Type in hex
UNKNOWN (0x565a4653)   %T Type in human readable form

These Might Interest You

  • #Alias alias perm="stat -c '%n %U:%G-%a'" #Function perm() { for ll in $@; do stat -c "%n %U:%G-%a" "$ll"; done; } Show Sample Output

    stat -c '%n %U:%G-%a' *
    snipertyler · 2014-05-03 04:56:23 0
  • This script compares the modification date of /var/lib/dpkg/info/${package}.list and all the files mentioned there. It could be wrong on noatime partitions. Here is non-oneliner: #!/bin/sh package=$1; list=/var/lib/dpkg/info/${package}.list; inst=$(stat "$list" -c %X); cat $list | ( while read file; do if [ -f "$file" ]; then acc=$(stat "$file" -c %X); if [ $inst -lt $acc ]; then echo used $file exit 0 fi; fi; done exit 1 ) Show Sample Output

    package=$1; list=/var/lib/dpkg/info/${package}.list; inst=$(stat "$list" -c %X); cat $list | (while read file; do if [ -f "$file" ];then acc=$(stat "$file" -c %X); if [ $inst -lt $acc ]; then echo used $file; exit 0; fi; fi; done; exit 1)
    pipeliner · 2010-09-20 18:10:19 0
  • perl version of "Wait for file to stop changing" When "FileName" has not been changed for last 10 seconds, then print "DONE" "10" in "(stat)[10]" means ctime. One have other options like atime, mtime and others.

    echo FileName | perl -nlE'sleep 1 while time-(stat)[10]<10' && echo DONE
    pung96 · 2015-05-09 14:58:41 0
  • Goes through all files in the directory specified, uses `stat` to print out last modification time, then sorts numerically in reverse, then uses cut to remove the modified epoch timestamp and finally head to only output the last 10 modified files. Note that on a Mac `stat` won't work like this, you'll need to use either: find . -type f -print0 | xargs -0 stat -f '%m%t%Sm %12z %N' | sort -nr | cut -f2- | head or alternatively do a `brew install coreutils` and then replace `stat` with `gstat` in the original command. Show Sample Output

    find . -type f -print0 | xargs -0 stat -c'%Y :%y %12s %n' | sort -nr | cut -d: -f2- | head
    HerbCSO · 2013-08-03 09:53:46 2

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: