Skip to content
TheChatArchiveThe Chat Archive
o3-mini· OpenAIHugging Face LMArena Human Preference 140K

统计当前Linux路径下有多少个文件夹

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Claudeclaude-sonnet-4-20250514’s answer.
  1. User

    统计当前Linux路径下有多少个文件夹

  2. Assistant

    下面介绍两种常用的方法来统计当前路径下的文件夹数目:

    1. 使用 ls 命令结合 grep 和 wc:

      ls -l | grep '^d' | wc -l
      
      • ls -l 列出当前目录的详细信息;
      • grep '^d' 用于筛选出以字母 d 开头的行(表示目录);
      • wc -l 则统计筛选后的行数。

      注意: 该命令会将 .(当前目录)列出来,如果你不希望统计当前目录本身,可以考虑使用第二种方法。

    2. 使用 find 命令:

      find . -maxdepth 1 -type d | wc -l
      
      • find . 表示从当前目录开始查找;
      • -maxdepth 1 限制查找深度为当前目录,不进入子目录;
      • -type d 指定查找目录类型;
      • wc -l 用于统计查找到的项目数。

      注意: 该命令同样会将当前目录 . 统计在内。如果你不想统计 .,可以用下面的命令过滤掉:

      find . -maxdepth 1 -type d ! -name '.' | wc -l
      

    选择适合自己需求的方法即可。

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.