Search code examples
bashfind

how to find the maximum depth to use for find . -maxdepth


I'm trying to create a loop so that the results of the find command increment the maxdepth by one each time so i can modify parent directory names and then subdirectory names on the next loop.

My thought was that I should know a way to find the 'maximum depth' so i can limit this loop to that, how I might I do that?


Solution

  • You need to traverse the directory hierarchy without a depth limit first.

    find . -type d -printf '%d\n' | sort -nr | head -1