9 command-line directory file-sorting
我希望列出目录的全部内容,包括子文件夹的内容,但按文件大小排序。到目前为止,我已经设法在列出和排序的同时仍然使用递归ls -lhSR
(这h
很好,但对我来说绝对不是必需的,只要我可以获得文件大小)。我可能会忽略一些明显的东西,或者问不可能的事情,但是这里的任何建议都将不胜感激。
pLu*_*umo 15
您可以使用查找:
find . -type f -printf "%s %P\n" | sort -n
Run Code Online (Sandbox Code Playgroud)
可选:要将字节值转换为人类可读的格式,请添加以下内容:
| numfmt --to=iec-i --field=1
Run Code Online (Sandbox Code Playgroud)
解释:
find in current directory (.) all files (-type f)
-printf: suppress normal output and print the following:
%s - size in bytes
%P - path to file
\n - new line
| sort -n: sort the result (-n = numeric)
Run Code Online (Sandbox Code Playgroud)
由于您没有指定特定的 shell,这里有一个使用 zsh 的 glob 限定符的替代方法
setopt extendedglob
Run Code Online (Sandbox Code Playgroud)
为递归。然后例如:
递归列出纯文件:
printf '%s\n' **/*(.)
Run Code Online (Sandbox Code Playgroud)递归列出纯文本文件,Ó rdered通过在压痕大号ength(即大小):
printf '%s\n' **/*(.oL)
Run Code Online (Sandbox Code Playgroud)递归名单纯文本文件,Ø rdered由德压痕尺寸:
printf '%s\n' **/*(.OL)
Run Code Online (Sandbox Code Playgroud)递归列出纯文件,按大小递减排序,并选择前 3 个结果:
printf '%s\n' **/*(.OL[1,3])
Run Code Online (Sandbox Code Playgroud)如果您还想要文件大小,那么您可以使用
du -hb **/*(.OL[1,3])
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1209 次 |
最近记录: |