linux shell file size linux shell file size shell shell

linux shell file size


filesize=$(stat -c '%s' testing.txt)


you can do it this way with ls (check man page for meaning of -s)

$ var=$(ls -s1 testing.txt|awk '{print $1}')

Or you can use stat with -c '%s'

Or you can use find (GNU)

$ var=$(find testing.txt -printf "%s")


size() {  file="$1"  if [ -b "$file" ]; then    /sbin/blockdev --getsize64 "$file"  else    wc -c < "$file"  # Handles pseudo files like /proc/cpuinfo    # stat --format %s "$file"    # find "$file" -printf '%s\n'    # du -b "$file" | cut -f1  fi}fs=$(size testing.txt)