Subject: Re: stat(1)
To: current-users@netbsd.org, Robert Elz <kre@munnari.OZ.AU>
From: Tero Kivinen <kivinen@ssh.fi>
List: current-users
Date: 12/30/2001 12:16:07
atatat@atatdot.net (Andrew Brown) writes:
> i wrote one once so that i could see more stuff. then i wrote another
> today because i read this thread. then i realized i could emulate my
> old script using my new one, and even ls (ls -lfdT actually, with -F
> and -L as options, and perhaps without -T).
I wrote one back in 1990/1991 which use used in some of the
cleanup task in our University. The main required feature was that if
no file names was given in the command line then it simply read file
names from the stdin. It also supported formatted output like yours...
I actually just dig it out from my old backups and updated it to
compile with modern c-compiler (prototypes, stdargs vs varargs,
snprintf instead of my own sprintfn etc). Seems to work (sources can
be found from the http://fireball.acr.fi/lstat-1.0.tar.gz):
----------------------------------------------------------------------
haste (12:12) ~/lstat-1.0>./lstat *
57621 13 0100644 1 kivinen wheel 12488 30.12.01 11:22:58 COPYING
57712 1 0100644 1 kivinen wheel 524 30.12.01 11:22:58 MANIFEST
57711 2 0100644 1 kivinen wheel 1126 30.12.01 11:24:08 Makefile
57710 1 0100644 1 kivinen wheel 249 30.12.01 11:22:58 README
57622 5 0100644 1 kivinen wheel 4559 30.12.01 11:44:40 errors.c
57716 2 0100444 1 kivinen wheel 1267 30.12.01 11:28:08 errors.h
57706 1 0100444 1 kivinen wheel 619 30.12.01 11:22:58 libdefaults.h
57627 10 0100444 1 kivinen wheel 9960 30.12.01 11:58:26 longgetopt.c
57630 4 0100444 1 kivinen wheel 3280 30.12.01 11:28:54 longgetopt.h
57708 60 0100755 1 kivinen wheel 61366 30.12.01 12:12:02 lstat*
57626 1 0100644 1 kivinen wheel 823 30.12.01 11:22:58 lstat.8
57624 14 0100644 1 kivinen wheel 13434 30.12.01 12:03:31 lstat.c
57628 9 0100644 1 kivinen wheel 8572 30.12.01 11:43:19 sprintfu.c
57714 1 0100444 1 kivinen wheel 928 30.12.01 11:38:59 sprintfu.h
haste (12:12) ~/lstat-1.0>./lstat -a lstat
4 57708 -rwxr-xr-x 1 kivinen wheel 157 40 61366 30.12.01 12:12:43 30.12.01 12:12:02 30.12.01 12:12:02 8192 120 /u/kivinen/lstat-1.0/lstat
haste (12:13) ~/lstat-1.0>find . -type f -name '*.c' | ./lstat -f 'file=%f size=%k'
file=/u/kivinen/lstat-1.0/sprintfu.c size=9
file=/u/kivinen/lstat-1.0/lstat.c size=14
file=/u/kivinen/lstat-1.0/longgetopt.c size=10
file=/u/kivinen/lstat-1.0/errors.c size=5
haste (12:13) ~/lstat-1.0>./lstat --help
Usage: lstat [-hSLDunaGw?] [-f<arg>] [-p<arg>] [-s<arg>] [-d<arg>] [-l<arg>] [-=<arg>] [-e<arg>] files...
-f +format Defines output format in printf style.
Format lstat field
%f file name (full path)
%N file name (last part)
%F relative path
%d major device number
%q minor device number
%i inode
%p protection in decimal
%o protetion in octal
%P protection in string
%n number of links
%u uid
%U user name
%g gid
%G group
%r major number for device
%R minor number for device
%s file size
%a access time (primary)
%A access time (secondary)
%m modification time (primary)
%M modification time (secondary)
%c status change time (primary)
%C status change time (secondary)
%x optimal blocksize for i/o opers
%b number of blocks allocated
%k size in kB
%l symbolic links value
%D print directory identifier if directory (/)
%L print link identifier if symbolic link ( -> )
%S print socket identifier if socket (=)
%E print executable identifier if executable (*)
Default string is :%5i %4k %07o %4n %-8U %-8G %10s %-17M
%F%D%L%S%E%l
-h +header Prints header
-p +primdate Defines primary date output format in printf style.
%a AD in 2 digit format
%A AD in 4 digit format
%m Month in number
%M Month in pervert yankee string (3 characters)
%d Day from beginning of month
%D Day from beginning of year
%w Day of week (Monday = 1)
%W Day of week as string
%h Hour in 24h clock
%H Hour in 12h clock
%n Minutes
%s Seconds
%S Seconds from 1.1.1970 00:00:00
%p am/pm
%P AM/PM
%z Time zone
Default string is :%S
-s +secdate Defines secondary date output format in printf style.
Use primdate for options
Default string is :%02d.%02m.%02y %02h:%02n:%02s
-S +stat Use stat to get information
-L +lstat Use lstat to get information
-D +date Print current date in secondary date format
-u +universal Print all times in gmt
-n +noreturn Do not add newline at end of line
-a +all Dump everything from (l)stat
+disclaimer I'm not responsible about brain damages generated from
using of this program and its options. All those options
are not my idea.
-d +directory Set directory string
-l +link Set directory string
-= +socket Set directory string
-e +executable Set directory string
-G +debug Turn debugging on
-w +warnings Turn warning messages on
+daemon Run in daemon mode (all errors to syslog)
-? +help Display this help text
haste (12:14) ~/lstat-1.0>
--
kivinen@ssh.fi
SSH Communications Security http://www.ssh.fi/
SSH IPSEC Toolkit http://www.ssh.fi/ipsec/