<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Calculating byte size in a directory in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588965#M103786</link>
    <description>Hi guys,&lt;BR /&gt;&lt;BR /&gt;  How do i used opendir and readdir to list out all the files in a directory...&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Henry</description>
    <pubDate>Mon, 25 Jul 2005 09:21:56 GMT</pubDate>
    <dc:creator>Henry Chua</dc:creator>
    <dc:date>2005-07-25T09:21:56Z</dc:date>
    <item>
      <title>Calculating byte size in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588960#M103781</link>
      <description>Hi guys&lt;BR /&gt;&lt;BR /&gt;Is it possible to write a program in C to calculate the byte size in a directory?&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Henry&lt;BR /&gt;</description>
      <pubDate>Sun, 24 Jul 2005 20:50:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588960#M103781</guid>
      <dc:creator>Henry Chua</dc:creator>
      <dc:date>2005-07-24T20:50:08Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating byte size in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588961#M103782</link>
      <description>Yes what you could do is write a program to open the directory read all the files in that directory and then use the stat() function in C which gives you a pointer to structure and get "st_size      file size in bytes" add all of them for all the files.&lt;BR /&gt;That will return you the total bytes used by the directory, something smiliar to du command&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;Rajeev</description>
      <pubDate>Sun, 24 Jul 2005 21:00:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588961#M103782</guid>
      <dc:creator>Rajeev  Shukla</dc:creator>
      <dc:date>2005-07-24T21:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating byte size in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588962#M103783</link>
      <description>As said, this boils down to combining these syscalls&lt;BR /&gt; &lt;BR /&gt;opendir(), readdir(), closedir(), stat()</description>
      <pubDate>Mon, 25 Jul 2005 01:34:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588962#M103783</guid>
      <dc:creator>Ralph Grothe</dc:creator>
      <dc:date>2005-07-25T01:34:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating byte size in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588963#M103784</link>
      <description>You can use stat() as,&lt;BR /&gt;&lt;BR /&gt;#include&lt;SYS&gt;&lt;BR /&gt;#include&lt;SYS&gt;&lt;BR /&gt;#include &lt;UNISTD.H&gt;&lt;BR /&gt;&lt;BR /&gt;main()&lt;BR /&gt;{&lt;BR /&gt;  int rc;&lt;BR /&gt;  struct stat buf;&lt;BR /&gt;  rc=stat("/tmp/block",&amp;amp;buf);&lt;BR /&gt;  if ( rc==0 ) {&lt;BR /&gt;  printf ("File size = %d bytes\n",buf.st_size);&lt;BR /&gt;  } else {&lt;BR /&gt;  printf ("Error\n");&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;cc -o block block.c&lt;BR /&gt;./block&lt;BR /&gt;&lt;BR /&gt;change name /tmp/block to some others.&lt;BR /&gt;&lt;BR /&gt;You can also use du -b &lt;FILENAME&gt;. Sample example c program is available as,&lt;BR /&gt;&lt;A href="http://www.phim.unibe.ch/comp_doc/c_manual/C/EXAMPLES/stat.c" target="_blank"&gt;http://www.phim.unibe.ch/comp_doc/c_manual/C/EXAMPLES/stat.c&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;hth.&lt;/FILENAME&gt;&lt;/UNISTD.H&gt;&lt;/SYS&gt;&lt;/SYS&gt;</description>
      <pubDate>Mon, 25 Jul 2005 03:37:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588963#M103784</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-07-25T03:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating byte size in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588964#M103785</link>
      <description>ere's one using awk&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;# cat /home/root/llsum&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;#&lt;BR /&gt;# Program: /scripts/llsum&lt;BR /&gt;# By: Geoff wild&lt;BR /&gt;# Usage: llsum &lt;FILES or="" directories=""&gt;&lt;BR /&gt;#&lt;BR /&gt;# Displays a truncated "ll" listing and displays size&lt;BR /&gt;# statistics of the files in the listing&lt;BR /&gt;#&lt;BR /&gt;# FYI&lt;BR /&gt;# %s means we are printing a string&lt;BR /&gt;# %d means we are printing an integer&lt;BR /&gt;#&lt;BR /&gt;# Awk field numbers:&lt;BR /&gt;# $1          $2 $3       $4           $5  $6  $7 $8    $9&lt;BR /&gt;# -rwx------   1 root     sys          774 Feb 24 12:07 llsum&lt;BR /&gt;#&lt;BR /&gt;ls -al $* |\&lt;BR /&gt;awk 'BEGIN { x=i=0; printf "%-16s%-10s%8s%8s\n",\&lt;BR /&gt;                "FILENAME","OWNER","SIZE","TYPE" }&lt;BR /&gt;&lt;BR /&gt;# Print owner, size, and type. Then sum the size.&lt;BR /&gt;$1 ~ /^[-dlps]/ { # line format for normal files&lt;BR /&gt;                printf "%-16s%-10s%8d",$9,$3,$5&lt;BR /&gt;                x = x + $5&lt;BR /&gt;                i++&lt;BR /&gt;                }&lt;BR /&gt;# If the line starts with a - its a regular file; d is&lt;BR /&gt;# directory, etc.&lt;BR /&gt;$1 ~ /^-/ { printf "%8s\n","file" } # standard file types&lt;BR /&gt;$1 ~ /^d/ { printf "%8s\n","dir" }&lt;BR /&gt;$1 ~ /^l/ { printf "%8s\n","link" }&lt;BR /&gt;$1 ~ /^p/ { printf "%8s\n","pipe" }&lt;BR /&gt;$1 ~ /^s/ { printf "%8s\n","socket" }&lt;BR /&gt;$1 ~ /^[bc]/ { #line format for device files&lt;BR /&gt;                printf "%-16s%-10s%8s%8s\n",$10,$3,"","dev"&lt;BR /&gt;        }&lt;BR /&gt;END { printf "\nThese files occupy %d bytes (%.4f Mbytes)\n",\&lt;BR /&gt; x, x / (1024*1024)&lt;BR /&gt;        printf "Average file size is %d bytes\n", x/i&lt;BR /&gt;}'&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff&lt;/FILES&gt;</description>
      <pubDate>Mon, 25 Jul 2005 07:39:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588964#M103785</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2005-07-25T07:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating byte size in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588965#M103786</link>
      <description>Hi guys,&lt;BR /&gt;&lt;BR /&gt;  How do i used opendir and readdir to list out all the files in a directory...&lt;BR /&gt;&lt;BR /&gt;Best regards&lt;BR /&gt;Henry</description>
      <pubDate>Mon, 25 Jul 2005 09:21:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588965#M103786</guid>
      <dc:creator>Henry Chua</dc:creator>
      <dc:date>2005-07-25T09:21:56Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating byte size in a directory</title>
      <link>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588966#M103787</link>
      <description>Man opendir. It has an example of the use of opendir and readdir.</description>
      <pubDate>Mon, 25 Jul 2005 11:14:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/calculating-byte-size-in-a-directory/m-p/3588966#M103787</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-07-25T11:14:19Z</dc:date>
    </item>
  </channel>
</rss>

