Shell 用于查找特定文件扩展名的脚本命令

Shell script command to find specific file extenions

我希望在我的 GH 提交历史记录中找到大文件,以便我可以找到这些文件并删除它们以减少我的存储库大小。

我从 this stack overflow thread 找到了一个 shell 脚本,它成功地从大到小列出了我的存储库中的文件

git rev-list --objects --all |
  git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' |
  sed -n 's/^blob //p' |
  sort --numeric-sort --key=2 |
  cut -c 1-12,41- |
  $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest

只需将其粘贴到我的命令行中即可输出以下内容

etc.
etc.
3886fa03848b  9.8MiB Python_scripts/cache/3948da8721027dc20b065e90c40573feff0bd651.json
ecc305ad772f  9.8MiB Python_scripts/cache/8c0751d1550c66250a435e83117deb36dcfd77ba.json
d25525e0a60c  9.8MiB Python_scripts/cache/6becf6f5e0c1547f43ef1ff7356d486e5358cbde.json
bd1cdcf0c45f  9.8MiB Python_scripts/cache/b3d00f1524a2edfe9397f60b8400fb5ac62037e7.json
df01689f9074  9.8MiB Python_scripts/cache/a44395ec06f9451db5f03f042141458ae977c261.json
217a805355fb  9.8MiB Python_scripts/cache/9ad253e8419bcc49278bc8da8f81d3e1ecdadaf6.json
72fa31033b72  9.8MiB Python_scripts/cache/800c9f1fea258738c3d992495a8f2f2b15ecc576.json
ea86a352aaf2  9.8MiB Python_scripts/cache/4a34d6bd3b25243bbac28c50304181555be1d6a9.json
806729ee0224  9.9MiB Python_scripts/cache/d0ab10701a112ad55e3131d765decbc01a10dc88.json
7ded9e2268c8  9.9MiB Python_scripts/cache/f357efd0808e655071e19f7d4e4671f1adfaf407.json
6db94f66e641  9.9MiB Python_scripts/cache/4f2e5392ee1018b63ee8982dbcae36edfcbfa9bb.json
f67da0d97ff6  9.9MiB Python_scripts/cache/282d8e0660282f045e846c52dbb7fddd3a3b5670.json
cac7d279b112   10MiB Python_scripts/cache/fab764e344ae8680dc445f11512cf065d0a2ad9c.json
af8c4882734f   10MiB Python_scripts/cache/46395651237d0c497f2772595dc2c9e91702b49b.json
78ae7b236719   11MiB articles/openinfra.html

我想为该脚本添加仅获取扩展名为 .json 的文件的功能,以便我可以找到所有提交哈希和 purge from the repo


线程顶部评论表明可以进一步过滤 (too low rep to post image):


目前我已经尝试过与 this find . -type f -name \*.rb 类似的方法,但是在 .rb 和 find . | grep *.json 上使用 .json 但是当将这两个添加到脚本时它失败了在命令行中 运行

所以我真的只是在寻找一条线,如果可能的话,它只会输出带有 .json 扩展名的文件(抱歉我缺乏 shell 脚本的经验!)

sed 行更改为

sed -n '/\.json$/ s/^blob//p'

仔细阅读 sed 和 awk,它们是基本 text-processing 工具,可轻松完成 metastasized-oneliner 范围内的任何任务。