#! /bin/bash declare -a line declare tot_bytes=0 declare tot_files=0 declare nf=0 declare temp=$(mktemp) ls -l $* | while read -a line; do nf=${#line[*]} if (( nf == 8 )); then if [[ "${line[0]:0:1}" == "-" ]]; then (( tot_bytes += ${line[4]} )) (( tot_files++ )) echo -e ${line[4]} "\t" ${line[7]} elif [[ "${line[0]:0:1}" == 'd' ]]; then echo -e '\t' ${line[7]} fi fi if (( nf == 1 )); then if echo ${line[0]} | grep -q '^.*:$'; then echo -e '***\t' ${line[0]} fi fi echo $tot_bytes $tot_files > $temp done read tot_bytes tot_files < $temp rm -f $temp echo Total: $tot_bytes bytes in $tot_files files