Jorge Vega Sánchez
Jorge Vega Sánchez

Reputation: 7590

List only directories names which match a pattern

I'm bit confused about the command or modifiers to obtain: List of directories (only directories, not including subdirectories) which names include a pattern.

Thanks in advance.

Upvotes: 46

Views: 41289

Answers (3)

Gilles Quénot
Gilles Quénot

Reputation: 184975

Use this little hack:

printf '%s\n' *pattern*/

if you prefer all on the same line :

echo *pattern*/

or using array :

arr=( *pattern*/ )
printf '%s\n' "${arr[@]%/}"

Upvotes: 8

choroba
choroba

Reputation: 241758

You are probably after the -d switch of ls:

ls -d *pattern*/
ls --directory *pattern*/

Upvotes: 75

Jorge Vega Sánchez
Jorge Vega Sánchez

Reputation: 7590

That's works for me.

But it outputs also the directory characteristics, permissions, date, etc. and I want to display only the directory name.

ls -t | grep '^d' | grep 'pattern'

Upvotes: 0

Related Questions