Created
January 5, 2015 06:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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