- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Calculating byte size in a directory
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-24-2005 01:50 PM
тАО07-24-2005 01:50 PM
Is it possible to write a program in C to calculate the byte size in a directory?
Regards
Henry
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-24-2005 02:00 PM
тАО07-24-2005 02:00 PM
Re: Calculating byte size in a directory
That will return you the total bytes used by the directory, something smiliar to du command
Cheers
Rajeev
- Tags:
- stat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-24-2005 06:34 PM
тАО07-24-2005 06:34 PM
Re: Calculating byte size in a directory
opendir(), readdir(), closedir(), stat()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-24-2005 08:37 PM
тАО07-24-2005 08:37 PM
Solution#include
#include
#include
main()
{
int rc;
struct stat buf;
rc=stat("/tmp/block",&buf);
if ( rc==0 ) {
printf ("File size = %d bytes\n",buf.st_size);
} else {
printf ("Error\n");
}
}
cc -o block block.c
./block
change name /tmp/block to some others.
You can also use du -b
http://www.phim.unibe.ch/comp_doc/c_manual/C/EXAMPLES/stat.c
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-25-2005 12:39 AM
тАО07-25-2005 12:39 AM
Re: Calculating byte size in a directory
# cat /home/root/llsum
#!/bin/sh
#
# Program: /scripts/llsum
# By: Geoff wild
# Usage: llsum
#
# Displays a truncated "ll" listing and displays size
# statistics of the files in the listing
#
# FYI
# %s means we are printing a string
# %d means we are printing an integer
#
# Awk field numbers:
# $1 $2 $3 $4 $5 $6 $7 $8 $9
# -rwx------ 1 root sys 774 Feb 24 12:07 llsum
#
ls -al $* |\
awk 'BEGIN { x=i=0; printf "%-16s%-10s%8s%8s\n",\
"FILENAME","OWNER","SIZE","TYPE" }
# Print owner, size, and type. Then sum the size.
$1 ~ /^[-dlps]/ { # line format for normal files
printf "%-16s%-10s%8d",$9,$3,$5
x = x + $5
i++
}
# If the line starts with a - its a regular file; d is
# directory, etc.
$1 ~ /^-/ { printf "%8s\n","file" } # standard file types
$1 ~ /^d/ { printf "%8s\n","dir" }
$1 ~ /^l/ { printf "%8s\n","link" }
$1 ~ /^p/ { printf "%8s\n","pipe" }
$1 ~ /^s/ { printf "%8s\n","socket" }
$1 ~ /^[bc]/ { #line format for device files
printf "%-16s%-10s%8s%8s\n",$10,$3,"","dev"
}
END { printf "\nThese files occupy %d bytes (%.4f Mbytes)\n",\
x, x / (1024*1024)
printf "Average file size is %d bytes\n", x/i
}'
Rgds...Geoff
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-25-2005 02:21 AM
тАО07-25-2005 02:21 AM
Re: Calculating byte size in a directory
How do i used opendir and readdir to list out all the files in a directory...
Best regards
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-25-2005 04:14 AM
тАО07-25-2005 04:14 AM
Re: Calculating byte size in a directory
- Tags:
- opendir