Reputation: 4406
I want to share a summary of a directory with file names and sizes in plain text.
This thread shows a file list with human-readable file sizes, e.g. on macOS:
$ du -h -d 10 14G ./190803 Aaah 13G ./190804 (no sound)
This post lists a file structure with a nice tree:
$ find . -print | 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 (no sound) | |_____DSC0018.MOV | |_____DSC0019.MOV | |_____DSC0020.MOV | |_____DSC0021.MOV | |_____DSC0022.MOV | |_____DSC0023.MOV | |____DSC_0017.MOV
How can I combine both and show the human-readable file size next to each item, file or folder, in the latter tree display?
Upvotes: 0
Views: 1043
Reputation: 304
An app which will do this fast and painlessly is GrandPerspective - it makes graphic maps of the folder sizes but can also save a text list. Free from SourceForge or low cost from the App store.
Upvotes: 0
Reputation: 4455
Try this:
find . -print0 |
xargs -0 -I% du -h "%" |
awk ' {
size = $1
$1 = ""
print $0, "(" size ")" }
' |
sed -e 's;[^/]*/;|____;g;s;____|; |;g'
If you want the file sizes up in the front of the line, you can try this instead:
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) }'
The print0
and -0
deals with cases filepaths with quotes, as in Getting error "xargs unterminated quote" when tried to print the number of lines in terminal .
Upvotes: 1