But 4k
is how many bytes the file consumes. If the file contains the letter 'A' followed by an EOF, it still consumes 4k on the disk even though the file can be contained in two bytes. I just don't understand why you need to make the distinction aside from an academic perspective. That said, you can use the
ls -l command wrapped in a shell script.
Something along the lines of (this is off the top of my head; I make no promises of its quality or that it will even work):
Code:
#!/bin/bash
total_size=0
for file in * ; do
file_size=$( ls -ld ${file} | awk '{print $5 }' )
echo "${file_size} ${file}"
((total_size=total_size+file_size))
done
echo "------------"
echo "Total size: ${total_size}"
Bear in mind, the script does not:
1. recognize directories as anything other than a regular file (in other words, no recursion)
2. count any hidden files (such as .bash_profile)
You'd need to flesh it out some more to do that, or search for a different tool.