Skip to main content
removed `cd` and subshell, thanks @terdon
Source Link
Freddy
  • 26.3k
  • 1
  • 27
  • 64

You could cd into the directory, print the files sizes in bytes using a loop with stat and sum the output with awk:

cd "$dir"
for i in $files; do
  stat -c '%s' "$i"
done | awk '{t+=$1}END{print t}'"$dir/$i"

If you don't want to change the current working directory , you could run the command in a subshell:

(cd "$dir"; for i in $files; do stat -c '%s' "$i"; done | awk '{t+=$1}END{print t}')

You could cd into the directory, print the files sizes in bytes using a loop with stat and sum the output with awk:

cd "$dir"
for i in $files; do
  stat -c '%s' "$i"
done | awk '{t+=$1}END{print t}'

If you don't want to change the current working directory , you could run the command in a subshell:

(cd "$dir"; for i in $files; do stat -c '%s' "$i"; done | awk '{t+=$1}END{print t}')

You could print the files sizes in bytes using a loop with stat and sum the output with awk:

for i in $files; do
  stat -c '%s' "$dir/$i"
done | awk '{t+=$1}END{print t}'
Source Link
Freddy
  • 26.3k
  • 1
  • 27
  • 64

You could cd into the directory, print the files sizes in bytes using a loop with stat and sum the output with awk:

cd "$dir"
for i in $files; do
  stat -c '%s' "$i"
done | awk '{t+=$1}END{print t}'

If you don't want to change the current working directory , you could run the command in a subshell:

(cd "$dir"; for i in $files; do stat -c '%s' "$i"; done | awk '{t+=$1}END{print t}')