我正在尝试在目录和子目录中查找按大小排序的文件扩展名。
像这样:
76K .pek ./Adobe Premiere Pro Preview Files/demo.PRV/1d860051-77c9-4acb-973e-3b6b4428c54e+57631ed274ffb879a432291c 48000.pek
18M .cfa ./Adobe Premiere Pro Preview Files/demo.PRV/1d860051-77c9-4acb-973e-3b6b4428c54e+57631ed274ffb879a432291c 48000.cfa
19M ./.git/objects/e6/66dcd00fc197154f89563f2f1aa508e2ab3b50
21M .mov ./Demo 2.mov
如果可能的话,还可以搜索排除一些目录,例如.git
答案1
我的系统上的 find 命令的工作方式如下
# find . -type f -ls
...
145890044 12192 -rw-rw-r-- 1 USER GROUP 239234 Jun 7 15:03 ./QA/Audits/scripts/MYFILE.pdf
...
find . -type f
查找当前目录和子目录中的所有文件
-ls
列出文件
如果你希望排除目录,可以使用 prune 开关https://stackoverflow.com/questions/1489277/how-to-use-prune-option-of-find-in-sh
大小位于输出的第 7 列。因此,如果我想对结果进行排序,我会这样做
# find . -type f -ls | sort -nr -k7
-n
数字
-r
反向顺序 (可选)
-k7
列号 7
答案2
我可以找到文件大小
$ find . -type f -print0 | xargs -0 du | sort -rn | head -10 | cut -f2 | xargs -I{} du -sh {}
346M ./Downloads/The Walking Dead S02E02 ... (dutch subs nl).avi
159M ./.local/share/Trash/files/funky chicken.mpg
117M ./Calibre Library/Robert Martin/cc.mobi
114M ./Dropbox/snapshots/monthly.tgz
114M ./Dropbox/snapshots/daily.tgz
114M ./Dropbox/snapshots/weekly.tgz
76M ./tmp/projects/onthisday/onthisday.tar.gz
76M ./snapshots/projects/weekly.3/onthisday/onthisday.tar.gz
76M ./snapshots/projects/weekly.2/onthisday/onthisday.tar.gz
76M ./snapshots/projects/weekly.1/onthisday/onthisday.tar.gz
和扩展计数
$ find . -type f -name "*.*" | grep -o -E "\.[^\.]+$" | sort | uniq -c | sort -rn
353 .JPG
53 .png
45 .mov
33 .DS_Store
15 .prproj
...
2 .MXF
1 .xmp
1 .psd
1 .mp4
1 .md
1 .m4a
1 .gitignore
1 .gitattributes
如何将两者结合起来得到count
max file size
extensions
?
答案3
我首先想到的是:
du -h --exclude=".git" <starting directory> | sort -h | grep -o "\.[:alnum:]+$"