BEGIN { LIMIT=100*1000 } $2 == "ls" || $1 == "dir" { next} $2 == "cd" && $3 == ".." { if (S[depth]<=LIMIT) { R+=S[depth] } S[depth]=0 depth -= 1 } $2 == "cd" && $3 != ".." { depth += 1; P[depth]=$3; } NF == 2 { for (i=1;i<=depth;i++) { S[i]+=$1 } } END { print R }