递归列出文件的文件夹和文件大小

问题描述 投票:0回答:2

我想共享目录的摘要,并以纯文本形式显示文件名和大小。

This thread显示具有人类可读文件大小(例如,在macOS上:

$ du -h -d 1014G ./190803 Aaah13G ./190804(无声音)

[This post列出了带有漂亮树的文件结构:

$查找。打印sed -e's; [^ /] * /; | ____; g; s; ____ |; |; g'。| ____。DS_Store| ____ 190803 Aaah| | ____ 190803 Aaah.mp4| | ____ DSC_0011.MOV| | ____ DSC_0012.MOV| | ____ DSC_0013.MOV| | ____ DSC_0014.MOV| | ____ DSC_0015.MOV| | ____ DSC_0016.MOV| ____ 190804(无声音)| | _____ DSC0018.MOV| | _____ DSC0019.MOV| | _____ DSC0020.MOV| | _____ DSC0021.MOV| | _____ DSC0022.MOV| | _____ DSC0023.MOV| | ____ DSC_0017.MOV

如何合并两者,并在后一个树状显示中的每个项目,文件或文件夹旁边显示人类可读的文件大小?

shell directory filesize ls
2个回答
1
投票

尝试一下:

find . -print0 | 
  xargs -0 -I% du -h "%" | 
  awk ' { 
      size = $1 
      $1 = "" 
      print $0, "(" size ")" }
  ' | 
  sed -e 's;[^/]*/;|____;g;s;____|; |;g'

如果要在行的开头放大文件大小,则可以尝试以下方法:

find . -print0 | xargs -0 -I% du -h "%" | awk ' { size = $1 ; $1 = ""; print $0, size }' | sed -e 's;[^/]*/;|____;g;s;____|; |;g' | awk ' {size=$NF ; $NF=""; printf("(%5s) %s\n", size, $0) }'

0
投票

您可以尝试以下方法:

for f in $(ls -R); do wc -c $f;done
© www.soinside.com 2019 - 2024. All rights reserved.