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 http://www.commandlinefu.com/commands/view/5815/advanced-ls-output-using-find-for-formattedsortable-file-stat-info From my .bash_profile -> http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html
Sample Output
[275:254 0:302] [davinci@www.askapache.com:0 +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
FS:
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

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?

commandlinefu.com 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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: