Reputation: 7590
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
Reputation: 184975
Use this little hack:
printf '%s\n' *pattern*/
if you prefer all on the same line :
echo *pattern*/
or using bash array :
arr=( *pattern*/ )
printf '%s\n' "${arr[@]%/}"
Upvotes: 8
Reputation: 241758
You are probably after the -d
switch of ls
:
ls -d *pattern*/
ls --directory *pattern*/
Upvotes: 75
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