Home > Software engineering >  Find non empty directories with condition on their names in linux
Find non empty directories with condition on their names in linux

Time:05-18

There's a directory that has several subdirectories. These subdirectories' names are the date that the subdirectory was created. Now I want to list the subdirectories created in 'June' of 2021 and are not empty, so their names all contain this: 202106*. How can I do this? The command I use to list non-empty directories is this:

find . -mindepth 1 -maxdepth 1 -not -empty -type d

But I don't know how to set the name condition.

CodePudding user response:

The name is specified by -name

find . -mindepth 1 -maxdepth 1 -not -empty -type d -name '202106*'

For more information read the find man page

CodePudding user response:

suggesting

find . -type d -path "*202106*" -not -empty
  • Related