1

I want to list only those directories which are a particular depth from current directory. Let's say depth=2

The directories listed can be:

./abc/abc
./xyz/xyz

If depth is 3

./mvd/123/abc

etc.

  • Does symbolic links to directories elsewhere count? – Kusalananda Oct 23 '18 at 5:21
  • @Kusalananda Yes it does – sidharth arya Oct 23 '18 at 5:50
3

find allows you to specify both a minimal and maximal recursion depth:

find . -mindepth 3 -maxdepth 3 -type d
3

Assuming that the depth is 2. You can use

find . -type d -maxdepth 2 -mindepth 2

Here type d option will list only directory.

maxdepth 2 and mindepth 2 will give all the directories and files with exact depth of 2.

Not the answer you're looking for? Browse other questions tagged or ask your own question.