[英]find the 5 largest (by number of lines) files at git repository
我的目標:我想開始從事一個新的 OpenSource 項目。 項目鏈接: https://github.com/dry-python/returns/tree/master/returns首先,我需要了解我必須使用哪些文件?
任務:任務是按代碼行數對文件進行排序,找到行數最多的 5 個文件。 我可以使用控制台中的什么命令來執行此操作?
我已經做了什么:
ls / returns-master | wc -l | sort -n | head -n 5
作為回應,我得到一個錯誤:
ls: returns-master: No such file or directory
17
首先查看 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
head -n6 | tail -n +2
:獲取wc
返回的前 6 個條目,其中包括total
中的第一個條目,我們使用tail
將其刪除。
perl -lane 'print $F[-1]'
:打印由空格分隔的最后一列(文件名)。
您需要一個支持**
glob 的 shell。 我認為zsh
默認情況下會這樣做,在bash
中你需要shopt -s globstar
。 您也可以嘗試sort
而不是gsort
。
wc -l **/*(.)| gsort -n
您可以添加| gtail -n 6
| gtail -n 6
只獲得前五名。
僅獲取.zsh
文件:
wc -l **/*.zsh | gsort -n
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.