[alt.sources.d] ls -lR summary generator

tchrist@convex.COM (Tom Christiansen) (12/02/89)

I thought a while before posting this.  I don't want to detract from 
ANYONE posting sources.  I think alt.sources is wonderful because
anyone can post whatever little tool they've been using to make their
lives easier.  I want to thank Liam R.E. Quin for his posting.  I 
think that the scaling on sizes (b, K, M) is interesting.

I do have some questions though.
  
In article <1989Dec2.015928.3612@sq.sq.com> lee@sq.com (Liam R. E. Quin) writes:
|THe enclosed little shell script uses sed and nawk to take the output of
|ls -l or ls -lR (sysV or BSD) and produce output that looks like
|Sep86 42.0K arp
|Sep86 16.4K biod
|Sep86 45.3K chown
|Dec87 (sym) config -> /usr/etc/config
|Sep86 24.3K cron

Let's see I've I understand this -- you're just rearranging ls -l output,
right?  You're squeezing the date and throwing out some other columns.
And are sizes the sizes really accurate?  I usually prefer to know 
blocks used then sizes by byte, for which you'd want the 'ls -sl'
output.  Otherwise you'll be charged for the holes in the files.
Dbm files are a good example of files with holes in them.

|which can then be printed in multiple columns (for example).
|
|It's an example of using awk to post-process ls output, something I seem
|to do once every couple of years...  Please, no perl one-liner equivalents!

How come?  Nawk isn't available via anonymous FTP or automatic UUCP
as perl is.  I would be willing to bet that more people can get 
perl than nawk, since nawk isn't free.  And the author himself admits in 
comments that there are various version of nawk, some of which would
make certain constructs work, others which would not.

Now I don't really think I could do it in just one line of perl, unless I
trimmed newlines :-).  I'd have to play with the date depending on ls's
output.  Or I could do the stats that 'ls -l' does myself and not worry.
But anyway, I'm pretty sure it would be substantially smaller than the
version.  If I really wanted to duplicate lsabbrev in perl, I might use
the a2p and s2p translators and work from there, although rewriting by
hand usually yields tighter code.

But probably for my purposes I'd just do this and skip awk and perl both:

ls -F -s -l | sed -n -e 's/\(....\).................................\(............\).\(.*\)/\1 \2 \3/p' | sort +0rn -1

yielding output beginning like this (from /etc):

 192 Oct  3 11:20 rpc.lockd*
 176 Oct 11  1988 restore*
 152 Oct 11  1988 xdump*
 144 Oct 11  1988 dump*
 144 Oct 11  1988 op*
 136 Nov 16  1987 timedc*
 136 Oct 11  1988 fsck*
 136 Oct 11  1988 inetd*
 128 Apr 11  1989 timed*
 128 Oct 11  1988 cron*

All sizes are in actual kilobytes used by the file.

If I wanted to muck with the dates, I'd probably put the whole
thing into perl rather than trying to figure out the logic in 
sed.  Plus it's hard to get the current year in sed.

|I also have a version of pr (sort of) that works out how many columns
|to use on a per-page basis, with which this is very effective.  Mail me
|if you want it -- it was written by a friend and posted (as "pf") to
|net.sources in 1984 I think.  Saves lots of paper, & good for C where
|the single brace at the end of the file might otherwise have been on a
|page by itself :-(

I posted a similar tool in perl to alt.sources a while back called "words".
This kind of thing does save paper.  And yes, mail me if you want it.

--tom

    Tom Christiansen                       {uunet,uiucdcs,sun}!convex!tchrist 
    Convex Computer Corporation                            tchrist@convex.COM
		 "EMACS belongs in <sys/errno.h>: Editor too big!"

tale@cs.rpi.edu (Dave Lawrence) (12/03/89)

In article <3620@convex.UUCP> tchrist@convex.COM (Tom Christiansen) writes:

   Nawk isn't available via anonymous FTP or automatic UUCP as perl
   is.  I would be willing to bet that more people can get perl than
   nawk, since nawk isn't free.

But GAWK is.  Anonymous FTP/UUCP to standard GNU repositories (prep,
tut, osu-cis, et al).  Very consistent with modern nawk.

Dave
-- 
   (setq mail '("tale@cs.rpi.edu" "tale@ai.mit.edu" "tale@rpitsmts.bitnet"))

lee@sq.sq.com (Liam R. E. Quin) (12/09/89)

In article <3620@convex.UUCP> tchrist@convex.COM (Tom Christiansen) writes:
about my little "lsabbrev" program:
>| The enclosed little shell script uses sed and nawk to take the output of
>| ls -l or ls -lR (sysV or BSD) and produce output that looks like
>| Sep86 42.0K arp
>Let's see I've I understand this -- you're just rearranging ls -l output,
>right? 
Correct.

> And are sizes the sizes really accurate?  I usually prefer to know 
> blocks used then sizes by byte, for which you'd want the 'ls -sl'
> output.  Otherwise you'll be charged for the holes in the files.

Well, it depends why you want to know.  One use is to produce a rather
terser summary of the "ls-lR" files at most ftp sites.  There, the size is
an indication of how long it'd take to ftp the file (over a busy SL/IP
serial connection) to the local machine.  You don't have the choice of
changing the options to ls here, especially if you're using anonymous uucp.

Another use is to keep a printed record of files that are on a tape.  The
size tells me how much space they are on the tape, and how large they
will be when they are restored, as most archiving software does not put
the holes back into the files.

So no, the sizes are a rough guide, that's all.


>|It's an example of using awk to post-process ls output, something I seem
>|to do once every couple of years...  Please, no perl one-liner equivalents!

>How come?  Nawk isn't available via anonymous FTP or automatic UUCP
>as perl is.
Well, GNU Awk is at least as available as perl, and seems to be somewhat
more stable.  And nawk is supplied with System V these days, and you can
get it for DOS (ugh) from MKS, and nawk is on the AT&T toolchest, so this
statement .

Also, I was trying to say that I wasn't interested in starting off yet
another "perl is better than awk because it takes less characters"
argument of the sort that is so off-putting to people who are not yet
familiar with perl.

>And the author himself admits in 
>comments that there are various version of nawk, some of which would
>make certain constructs work, others which would not.
And every perl program works on every version of perl, and there are no
incompatible features, eveon on DOS or the 286, right?

>[sed script]
>yielding output beginning like this (from /etc):
> 192 Oct  3 11:20 rpc.lockd*
> 176 Oct 11  1988 restore*

Actually I did start with a sed script...
Trouble is, the ls -lR files on uunet, etc., are not in ls -FsRl format.
Also, the data in lsabbrev ouptput is in columns of equal width, and is
terser even if files are several megabytes large:
> 128 Oct 11  1988 cron*  < your sed script
> Dec89 24.3K OUT.3	  < lsabbrev

>|I also have a version of pr (sort of) that works out how many columns
>|to use on a per-page basis, [...]

>I posted a similar tool in perl to alt.sources a while back called "words".
>This kind of thing does save paper. [...]
Well, that was the idea.  I wrote "lsabbrev" to print out a huge ls -lR
listing with "pfm" putting as many columns on the page as would fit.
That's why I wanted it as narrow as possible.

I've had lots of requests for "pfm", so I have sent it to comp.sources.misc
for ++Brandon peruse and maybe post.

>		 "EMACS belongs in <sys/errno.h>: Editor too big!"
Perl is small and elegant, I suppose?   :-)			:-(

Lee
-- 
Liam R. Quin, Unixsys (UK) Ltd [note: not an employee of "sq" - a visitor!]
lee@sq.com (Whilst visiting Canada from England, until Christmas)
 -- I think I'm going to come out at last...
 -- What?  Admit you're not a fundamentalist Jew?  They'll *crucify* you!  :-)

lee@sq.sq.com (Liam R. E. Quin) (12/15/89)

(Bob Desinger) bd@hp-ses.SDE.HP.COM wrote (in alt.sources):
>Liam R. E. Quin (lee@sq.sq.com) writes:
>> I also have a version of pr (sort of) that works out how many columns
>> to use on a per-page basis, with which this is very effective.
>
>I tried to mail to ask for `pf', but the mailer at a.cs.uiuc.edu
>barfed:

I have submitted it to Brandon the Benign for inclusion in com.sources.misc.

Lots of other people mailed me, too.
I don't know why you can't mail to lee@sq.com.

Lee
-- 
Liam R. Quin, Unixsys (UK) Ltd [note: not an employee of "sq" - a visitor!]
lee@sq.com (Whilst visiting Canada from England, until Christmas)
 -- I think I'm going to come out at last...
 -- What?  Admit you're not a fundamentalist Jew?  They'll *crucify* you!  :-)