Skip to content

Instantly share code, notes, and snippets.

@hjhart
Last active November 6, 2017 19:39
Show Gist options
  • Save hjhart/432689a75b358d6c26feb276843c4f72 to your computer and use it in GitHub Desktop.
Save hjhart/432689a75b358d6c26feb276843c4f72 to your computer and use it in GitHub Desktop.
Joyent Manta, list directories and their recursive size within
# function happily borrowed from https://unix.stackexchange.com/a/259254
bytesToHuman() {
b=${1:-0}; d=''; s=0; S=(Bytes {K,M,G,T,E,P,Y,Z}iB)
while ((b > 1024)); do
d="$(printf ".%02d" $((b % 1024 * 100 / 1024)))"
b=$((b / 1024))
let s++
done
echo "$b$d ${S[$s]}"
}
mkdir manta_contents
for dir in $(mls)
do echo $dir
mkdir -p manta_contents/$dir
mls -l $dir >> manta_contents/$(echo $dir)/files
for subdir in $(mfind -t d /wanelo/stor/$dir)
do
mls -l $subdir >> manta_contents/$(echo $dir)/files
done
done
for dir in $(mls)
do
bytes=$(cat manta_contents/$dir/files | awk '{ print $4 }' | paste -sd+ - | bc)
echo $dir $bytes $(bytesToHuman $bytes)
done
done
.joyent/ 41693 40.71 KiB
backup/ 62206189 59.32 MiB
backups/ 4732683606342 4.30 TiB
cores/ 612648223 584.26 MiB
demo/ 22077652 21.05 MiB
images/ 298759686 284.91 MiB
postgres/ 33733185216 31.41 GiB
sitemaps/ 6346928762 5.91 GiB
staging/ 5547741 5.29 MiB
tmp/ 163482942 155.90 MiB
@hjhart
Copy link
Author

hjhart commented Nov 6, 2017

To dive deeper into a subdirectory,

export BASE_DIR=images
export MANTA_USER=wanelo
mkdir -p manta_contents
for dir in $(mls $BASE_DIR)
  do echo $dir
	mkdir -p manta_contents/$BASE_DIR/$dir
  mls -l $BASE_DIR/$dir >> manta_contents/$BASE_DIR/$(echo $dir)/files
  for subdir in $(mfind -t d /$MANTA_USER/stor/$BASE_DIR/$dir)
    do
      mls -l $subdir >> manta_contents/$BASE_DIR/$(echo $dir)/files
  done
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment