Find the answer to your Linux question:
Results 1 to 4 of 4
hi, again in trouble.. how can i get the directory size in bytes in 'c' Language on linux????? the directory may contain files or subfolders... i think the dirent.h file ...
  1. #1
    Just Joined!
    Join Date
    Sep 2004
    Posts
    21

    How to find Directory Size ?

    hi,

    again in trouble..

    how can i get the directory size in bytes in 'c' Language on linux?????
    the directory may contain files or subfolders...

    i think the dirent.h file has to be included..

    but i dont know about wat function shoud i use to get the directory size in bytes...

    Help ME Out.........URGENT!

  2. #2
    Linux Guru sdousley's Avatar
    Join Date
    Feb 2004
    Posts
    1,789
    You need to use the du command. not sure if u need to be root to use this, but if it fails as a standard user su and give it a go as root. tho u may wanna check out the man pages for it to see what tags to ass to make it show the size in megabytes rather than bytes!

    edit: I have just gone back to linux to find the flag u want to use

    If u type:
    Code:
    du -h
    this will disply the disk usage of the current folder in human readable format (megabytes etc.
    "I am not an alcoholic, alcoholics go to meetings"
    Registered Linux user = #372327

  3. #3
    Just Joined!
    Join Date
    Jan 2007
    Posts
    12
    Or if you don't wanna see all of the sub-directories you can expand on this by typing...

    Code:
    du -h | grep -v '/' | awk '{print $1}'

  4. #4
    Just Joined!
    Join Date
    Jan 2010
    Posts
    1
    This is much faster if you want only the total size.
    Code:
    du -h | tail -n 1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...