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

Re: How to find dirs with single item



Reco wrote:
> Dennis Wicks wrote:
> > I'd like to be able to scan a Volume or directory and find 
> > all directories that have only one item in them. Either 
> > directory or file.
> 
> Try this (yep, links should be 3, not 1):
> 
> find <where_you_want_to_search> -type d -links 3

Good try.  That will almost work.  Using -links 3 will find any
directory that has exactly one directory in it.  But it won't match
exactly one file in a directory.

It is the ".." link from the subdirectory up that increases the link
count from 2 to 3.  But files don't create links to the directory and
therefore don't increase the link count.

The size of the directory isn't of help either.  I think the only way
is to actually list each directory in turn and count.  Perhaps someone
else will have a better idea.

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: