在 git 存储库中找到 5 个最大的(按行数)文件

find the 5 largest (by number of lines) files at git repository

我的目标: 我想开始从事一个新的 OpenSource 项目。 link 的项目:https://github.com/dry-python/returns/tree/master/returns 首先,我需要了解我必须使用哪些文件?

任务: 任务是按代码行数对文件进行排序,找到行数最多的 5 个文件。 我可以在控制台中使用什么命令?

我已经做了:

  1. 已将存储库文件上传到我的本地计算机中名为“returns-master”的目录中
  2. 运行命令:
ls / returns-master | wc -l | sort -n | head -n 5

作为响应,我得到一个错误:

ls: returns-master: No such file or directory
17

您需要一个支持 ** glob 的 shell。我认为 zsh 默认情况下,在 bash 中你需要 shopt -s globstar。您也可以尝试 sort 而不是 gsort

wc -l **/*(.)| gsort -n

您可以添加 | gtail -n 6 以获得前五名。

仅获取 .zsh 个文件:

wc -l **/*.zsh | gsort -n

首先查看 git 存储库。然后在磁盘上找到想要的文件:

find /path/to/your/copy/of/repo -type f | xargs wc -l | sort -gr | head -n6 | tail -n +2 | perl -lane 'print $F[-1]'

此处,find 将签出的 git 存储库中的文件列表传递给 xargs,后者将它们提供给 wc -l,后者计算行数。
sort -gr : 按第一列(行数)倒序排列。
head -n6 | tail -n +2 :获取 wc 返回的前 6 个条目,其中包括第一个带有 total 的条目,我们使用 tail.
将其删除 perl -lane 'print $F[-1]' :打印由空格分隔的最后一列(文件名)。