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

Re: Unix 101: ls with file count



On Mon, Jun 24, 2002 at 10:41:48PM -0500, Kent West wrote:
> Okay, back to Unix 101 for me.
> 
> How do I produce a directory listing followed by a count of files and 
> directories?
> 
> ls | wc
> 
> only produces a count without listing the files, and it doesn't 
> distinguish between files and directories. What I'd like is something 
> like this:
> 
> westk03[westk]:/home/westk> ls
> DOCS          evolution
> Desktop       lang
> HOCHZEIT.MPG  lynx_bookmarks.html
> INSTALLERS    mbox
> MMEDIA        mnt
> Mail          nsmail
> Nautilus      oh brother where art thou - down by the river allison kra.wav
> PILOT         plugin130_01.trace
> bin           progtool
> calc.perl     tmp
> clock         vmware
> doc           www
> 
> 16 directories
> 8 files
> --------
> 24 total
> 
> Thanks!
> 
> Kent

Probably best to do it in two steps.

1) Simply call ls to do the first bit

2) Calculating the totals.  Read the bash manpage for how to use
variables and how to add them together.  You'll probably want to use
something like `find . -type d -maxdepth 1 | wc -l` to count directories
and `find . -type f -maxdepth 1 | wc -l` to count files.

- Chris


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



Reply to: