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

Re: How to find dirs with single item



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.

What is a "Volume"?  I immediately think of an LVM volume group.  But
that isn't exposed as a file system.

Technically speaking a directory can never have only one item in them
because all directories always start with two items in them when they
are created empty.  All directories are created with "." and ".."
entries.  Therefore you are looking for directories that contain
exacty three entries.  Normally you won't see the dot entries because
they are hidden files unless you give ls the -a option.

Normally I would always say use "find".  But there isn't a test that
matches what you want exactly.

Therefore the way I would do this would be to write a script.  That
makes answering this quickly too complicated for an on the fly
response.  But basically use 'find' to find all directories.  Then
list each directory to see if it matches your criteria.  I will leave
that exercise to someone with more time on their hands. :-)

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: