LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   finding size of total files in a directory (https://www.linuxquestions.org/questions/linux-newbie-8/finding-size-of-total-files-in-a-directory-274888/)

blackzone 01-06-2005 11:58 PM

finding size of total files in a directory
 
how do I find the total file size in a directory.

while using "du" it don't do the actual file size.

for example any file over 1 byte will use 4096 bytes of space(becuase of node)?

Linux~Powered 01-07-2005 12:04 AM

Code:

du -ab
Will show the size of the files in bytes and the total size of the directory at the end.

blackzone 01-07-2005 01:08 AM

it won't really show file size though

on my system any file less than 4k will use 4k of space. du shows disk usage not file size.

It woult be approximately the same anyway. but is there a way to show total file size in a directory?

Dark_Helmet 01-07-2005 03:01 AM

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.


All times are GMT -5. The time now is 12:30 PM.