Listing only directories in UNIX

前端 未结 20 891
青春惊慌失措
青春惊慌失措 2020-12-12 09:40

I want to list only the directories in specified path (ls doesn\'t have such option). Also, can this be done with a single line command?

20条回答
  •  醉话见心
    2020-12-12 10:18

    find specifiedpath -type d

    If you don't want to recurse in subdirectories, you can do this instead:

    find specifiedpath -type d -mindepth 1 -maxdepth 1

    Note that "dot" directories (whose name start with .) will be listed too; but not the special directories . nor ... If you don't want "dot" directories, you can just grep them out:

    find specifiedpath -type d -mindepth 1 -maxdepth 1 | grep -v '^\.'

提交回复
热议问题