Skip to content

Instantly share code, notes, and snippets.

@shang-lin
Created January 5, 2015 06:33
Show Gist options
  • Save shang-lin/a2b6ab7decc22a2f2095 to your computer and use it in GitHub Desktop.
Save shang-lin/a2b6ab7decc22a2f2095 to your computer and use it in GitHub Desktop.
How to obtain file sizes from ls output on the command line
# ls -s displays the size of files, in blocks, followed by the file name.
# For convenience, I am setting the block size to 1024 bytes, or 1 kilobyte.
# The output of ls -s is piped to an awk command that incrementally adds the file sizes and displays the total.
ls --block-size=1024 -s /path/to/files | awk '{ total += $1 }; END { print total }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment