找指定位置下的目錄

想找到指定位置下的目錄,但不要再深入。指定位置下的目錄是這樣的

/tmp/location
  +-- dir1
    + dir11
  +-- dir2
    + dir21
  foo.txt

我預期是只看到 dir1 跟 dir2,所以我用 find

find /tmp/location -type d -print

結果我找到的是

/tmp/location
/tmp/location/dir2
/tmp/location/dir2/dir21
/tmp/location/dir1
/tmp/location/dir1/dir11

find 的輸出跟我預期的不相符啊,我又不想用 ls 處理,後來找到 -maxdepth -mindepth 這兩個參數,搭配起來使用就可以了。

find /tmp/location -maxdepth 1 -mindepth 1 -type d -print

這樣就會是我需要的 dir1 跟 dir2

/tmp/location/dir2
/tmp/location/dir1

又學到一課,謝謝你 find