[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Unix 101: ls with file count



Vineet Kumar wrote:

<various snippings for brevity>

alias dolsa='ls -la --color | more ; echo -------------------; echo `ls -la | grep ^d | wc -l` Directories; echo `ls -la | grep ^- | wc -l` "File(s)" ; echo `ls -la | grep ^l | wc -l` "Symbolic Link(s)"; echo 1 Byte Count ; echo `ls -la | wc -l` Total Items'


Glad you got that working! But it's a bit hairy, and would be a headache
to change, if the need ever arose. How about this, instead: make a
script called ~/bin/dolsa that looks like this:

#!/bin/sh

ls -la --color | more
echo -------------------
echo `ls -la | grep ^d | wc -l` Directories
echo `ls -la | grep ^- | wc -l` "File(s)"
echo `ls -la | grep ^l | wc -l` "Symbolic Link(s)"
echo 1 Byte Count
echo `ls -la | wc -l` Total Items

<EOF>

You could also optimize it (though I'm sure it runs fast enough that the
time is trivial) by storing the output of ls -la instead of calling it 3
times and by using grep -c instead of piping to wc -l . You could also
wrap the whole thing in $( ) | more instead of just piping the ls output
to more. Better yet, use less. Better still, use
${PAGER:-/usr/bin/pager} .

But don't stress out about it. These suggestions are the type that a
software engineer sees but that really don't make much difference to
the user. If you got it working, that's what counts!


I really like your ideas. Thanks!

Kent



--
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: