Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Listing the average file size for all subfolders (+listing subfolders without ls or find)
A tiny "Frankenstein monster" one liner, adding a little bit from several sources/blogs/blog comments:
lsf | while read d ; do find ./"$d" -iname "*.*" -type f -printf "%k\n" | gawk '{sum += $1; n++;} END {print sum/n;}' |sed "s|$| -- $d|" ; done | sort -n
Where the first "command", "lsf" is actually a custom function:
I think it's a little bit better to parse than "ls -1 -d /*" or "find . -maxdepth 1 -type d". Only because it doesn't have two slashes after each folder name or "./" before. Even though the latter isn't that bad.
To get the ratios of "average of deviations above average" per deviations above average:
lsf | while read d ; do AVG="$(find ./"$d" -maxdepth 1 -iname "*.*" -type f -printf "%k\n" | gawk '{sum += $1; n++;} END {print sum/n;}' | sed 's|\..*||')k" ; devs=$(find ./"$d" -iname "*.*" -type f -maxdepth 1 -size +$AVG | wc -l) ; devsize=$(find ./"$d" -maxdepth 1 -iname "*.*" -type f -size +$AVG -printf "%k\n" | gawk '{sum += $1; n++} END {print sum/n;}' | sed 's|\..*||') ; echo "$(echo "${devsize:-1}/${devs:-1}" | bc -l) -- $AVG -$d "; done | sort -n
Can give lots of errors due to division by 0 and such things. Warning: I'm not good at math.
lsf | while read d ; do find ./"$d" -iname "*.*" -type f -printf "%k\n" | gawk '{sum += $1; n++;} END {print sum/n;}' |sed "s|$| -- $d|" ; done | sort -n
Where the first "command", "lsf" is actually a custom function:
Code:
lsf () { for f in * ; do [ -d "$f" ] && echo $f ; done }
To get the ratios of "average of deviations above average" per deviations above average:
lsf | while read d ; do AVG="$(find ./"$d" -maxdepth 1 -iname "*.*" -type f -printf "%k\n" | gawk '{sum += $1; n++;} END {print sum/n;}' | sed 's|\..*||')k" ; devs=$(find ./"$d" -iname "*.*" -type f -maxdepth 1 -size +$AVG | wc -l) ; devsize=$(find ./"$d" -maxdepth 1 -iname "*.*" -type f -size +$AVG -printf "%k\n" | gawk '{sum += $1; n++} END {print sum/n;}' | sed 's|\..*||') ; echo "$(echo "${devsize:-1}/${devs:-1}" | bc -l) -- $AVG -$d "; done | sort -n
Can give lots of errors due to division by 0 and such things. Warning: I'm not good at math.
Total Comments 0