1

Is there any script or command to get the FOLDER size in BYTES or BITS so that every small change in the files in the folder is reflected by checking the Folder size in SOLARIS/

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
TommyT
  • 1,707
  • 3
  • 17
  • 26
  • It's a bad idea to do this; the "information" is pretty bogus, as the "size" of a folder is not well-defined in UN*X in general; do you mean the size of the directory inode (i.e. the cumulative sum of filenames/attributes) ? do you mean the sum of sizes of all files in the directory hierarchy underneath (and if so, what's the "size" of a file given there can be hard/soft links, sparse files, and storage allocation is done in units of frags/blocks not bytes) ? If you've got ZFS, then due to compression and copy-on-write, "net" numbers are even more meaningless ... – FrankH. Aug 05 '13 at 21:17

2 Answers2

1

The directory size doesn't change when you add few bytes to files. Files are allocated in fragments / blocks.

Should you want the cumulative size of all files in a directory, you have to compute it yourself. See https://superuser.com/a/603302/19279

Note that this size doesn't represent what the files are using, which is usually larger but can also be smaller depending on various factors.

Edit:

Here is a simplified solution giving the size in bytes:

#!/bin/sh
find ${1:-.} -type f -exec ls -lnq {} \+ | awk '{sum+=$5} END{print sum}'
Community
  • 1
  • 1
jlliagre
  • 29,783
  • 6
  • 61
  • 72
  • Awesome .. Could you give me some pointers on how I can edit the script in the link to get the size in BYTES or BITS – TommyT Jul 26 '13 at 18:29
  • Answer updated. Should you really want the size in bits, just multiply sum by 8 in the last statement `print sum*8`. – jlliagre Jul 26 '13 at 18:37
  • and by the way, the usage when you consider awesome a reply to one of your question is to accept it ... – jlliagre Jul 26 '13 at 21:24
0

du -sk foldername is a Pop Favorite. Just multiply the result by 1024 for #/bytes.

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • But the output never changes if I add two or three lines in the files inside the folder ... so the answer is mostly going to be the same .. I am trying to get even a small change in that folder by getting its change in size in bytes or bits – TommyT Jul 25 '13 at 22:08