filestat - a tool for using stat(2) information in shell scripts

filestat is a command line tool which prints file status information such as modification and access times. You can think of it as an infinatly customizable version of ls.  It is also particularly useful in shell scripts to rename files to names based on their creation time.

Examples

Move all log files to a history directory.  Rename them to the date of last modification of the log file

    #!/bin/sh

    for logfile in /var/log/* ; do
        cmd=`filestat ´mv %N /admin/loghistory%N/%M[%Y%m%d]´ $logfile`
        $cmd
    done

Print file names followed by the number of days since they were created.

    filestat '%N %.M#%d#' *

Get the source

The latest package filestat-2.0.1.tar.Z
An older version: filestat-2.0.tar.Z
Even older: filestat-1.0.tar.Z


Note: The manual page below is produced using man2html. There are several formatting gliches which are unavoidable at this time. A correctly formatted manual page is in the file filestat.txt in the package.



       filestat - prints file information in an easy to use fash-
       ion

SYNOPSIS
       filestat [-g]  file ...

DESCRIPTION
       Filestat provides a convenient way of printing file infor-
       mation so that it can be used in shell scripts.

OPTIONS
       -g        Print times in GMT rather than local time.

FORMAT DIRECTIVES
       The    string  is  a printf-like string based on the
       options of the stat command.    Directives  control  which
       members of the stat structure to print.

       %b    512 byte blocks allocated

       %v    device

       %g    gid

       %i    inode

       %l    link count

       %k    file kind (see stat(2) for more information)

       %K    size in KB

       %o    mode (in octal)

       %N    file name

       %p    permissions (in octal)

       %r    rdev

       %s    size

       %u    uid

       %A[fmt]
             access time using fmt as a subformat

       %C[fmt]
             status change time using fmt as a subformat

       %M[fmt]
             modification time using fmt as a subformat
             mat for the strftime(3)  subroutine.   The  strftime
             directives are reproduced here for convenience only.

             %a     locale's abbreviated weekday name

             %A     locale's full weekday name

             %b     locale's abbreviated month name

             %B     locale's full month name

             %c     locale's appropriate date and time  represen-
                    tation

             %C     locale's  date  and  time rep. as produced by
                    date(1)

             %d     day of month ( 01 - 31 )

             %D     date as %m/%d/%y

             %e     day of month (1-31)

             %h     locale's abbreviated month name.

             %H     hour ( 00 - 23 )

             %I     hour ( 01 - 12 )

             %j     day number of year ( 001 - 366 )

             %m     month number ( 01 - 12 )

             %M     minute ( 00 - 59 )

             %n     same as new-line

             %p     locale's equivalent of either AM or PM

             %r     time as %I:%M:%S [AM|PM]

             %R     time as %H:%M

             %S     seconds ( 00 - 61 ), allows for leap seconds

             %t     same as a tab

             %T     time as %H:%M:%S

             %U     week of year ( 00 - 53 ), Sunday is first day
                    of week 1

                    day of week 1

             %x     locale's appropriate date representation

             %X     locale's appropriate time representation

             %y     year within century ( 00 - 99 )

             %Y     year as ccyy ( e.g. 1986)

             %Z     time zone name or no characters  if  no  time
                    zone exists

       %A#fmt#  %C#fmt#  %M#fmt#
             alternate  way  of  specifying subformat.  Easier to
             quote in scripts.

       %{+}A %{+}C %{+}M followed by neither [ or #
             Use default subformat of "%Y%m%d".  If + modifier is
             added, then use %Y%m%d%H%M%S.

       %.A#fmt#  %.C#fmt#  %.M#fmt#
             As  above,  but  using  time relative to the current
             time.  Only the %Y, %d, %H, %M  and  %S  sub-formats
             make sense when using relative time.

       %d    Same as %M[%d].

       %H    Same as %M[%H].

       %j    Same as %M[%j].

       %m    Same as %M[%m].

       %-M   Same as %M[%M].

       %S    Same as %M[%S].

       %{-}T Same  as  %M[%H:%M:%S].  If - modifier is used, then
             same as %M[%H%M%S].

       %w    Same as %M[%w].

       %y    Same as %M[%y].

       %Y    Same as %M[%Y].

SEE ALSO
       stat(1), stat(2), strftime(3)

EXAMPLES
       filestat '%M#%Y%m%d %N' *
           produce a listing of files and their age in days
       filestat '%N %.A#%d' *
           produce a listing of files and the number of days
           ago they were last accessed.
       cp foo.c filestat %N-%M#%Y%m%d' foo.c`
           copy foo.c to foo.c-YYYYMMDD

AUTHOR
       Tony Aiuto  <tony.aiuto@gmail.com>












































Comments and money to  tony.aiuto@gmail.com