[Gllug] Locating Subdirectories

Stig Brautaset stig at brautaset.org
Wed Jul 28 08:20:28 UTC 2004


On Wed, Jul 28, 2004 at 08:23:21AM +0100, Nix wrote:
> >> I need to obtain the names of all the subdirectories in the
> >> current directory.  
...
> > 
> > find . -type d -maxdepth 1 -printf "%f\n"
> 
> Why -printf, not just -print?
>
> (Or, with GNU find, nothing at all as the operation, as -print is the
> default?)

Because he wanted the names of the subdirectories, not their paths.

(As I'm testing to verify this I realise it has a bug though. Fixed by:
  find . -type d -maxdepth 1 -printf "%f\n" | sed '1D'
   - or -
  find . -type d -mindepth 1 -maxdepth 1 -printf "%f\n" 
)
  

Stig
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list