How to generate a list of directories that has names starting with "A" and ending with "O"?

How do I use the find command to generate a list of directories whose names starts with "A" and ends with "O"?

Upvotes: 0

Views: 55

Answers (2)

Utsav
Utsav

Reputation: 5918

You can use
Case Sensitive - find . -type d -name "AO" 2>/dev/null
Case Insensitive - find . -type d -iname "A
O" 2>/dev/null
We can use -i to ignore the case.

Upvotes: 0

Kusalananda
Kusalananda

Reputation: 15633

The answer is

$ find . -type d -name "A*O"

The -type d option tells find to only output directory names, and the -name "A*O" option further restricts those names to those matching the pattern A*O (i.e. starting with A and ending with O). It does this in the current directory (.) and will recursively enter any directory therein and performs the same task.

Upvotes: 1

Related Questions