Sponsored Content
Top Forums Shell Programming and Scripting Calculate total space, total used space and total free space in filesystem names matching keyword Post 302374505 by jim mcnamara on Tuesday 24th of November 2009 05:16:15 PM
Old 11-24-2009
I don't get why you ask since you only accept 'oracle' and nothing else. It is not needed. I am assuming that there are directories in your file system(s) named 'oracle'
If the match is really '*oracle*' then change this code to match:

Code:
find / -name 'oracle' -type d |
while read fname
do
  bdf $fname 
done | awk '{ s += $1 } END { print "Total Space: ", s, " Used Space: ", s/NR, " Free Space: ", NR } '

I don't know what NR is supposed to do. NR is the number of records. It has nothing to do with free space or used space either. Used space is produced by bdf. Free space is total - used. s/NR divides the free space by the number of directories or filesystems.
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

df+du=Total space allocated(for a file system)

Hi All, Will df+du=Total space allocted for a file system?? Is the above correct. Please correct me If iam wrong. In one my programs the above is not happening. Please help me out. Many thanks. Regards, Manas (2 Replies)
Discussion started by: manas6
2 Replies

2. AIX

used PPs not match the total disk space showed by df

Hi, I see from lsvg the total used PPs is 1050 (67200 megabytes), but when I check the disk space with df command I can only see 31G total space, can somebody tell how this come? Thanks! Victor # lsvg rootvg # lsvg rootvg VOLUME GROUP: rootvg VG IDENTIFIER: ... (2 Replies)
Discussion started by: victorcheung
2 Replies

3. Red Hat

Total space Determination

Hi experts, # df -h Filesystem Size Used Avail Use% Mounted on /dev/hda9 3.8G 1.7G 2.0G 46% / none 369M 0 369M 0% /dev/shm /dev/hda10 2.0G 33M 1.8G 2% /tmp /dev/hda12 1.4G 1.2G 260M 82% /usr I used df -h... (3 Replies)
Discussion started by: William1482
3 Replies

4. Solaris

swap size, total disk space

Hi experts, In my solaris system when i run the command df -h i got the below response.I have some confusion which i want to share with you guys.1)there are two SWAP file system shows are they same or different?2)if i want to count the total disk space should i take both the swap space or only... (2 Replies)
Discussion started by: rafiassam
2 Replies

5. Solaris

command to get the total disk space (available + free)

is there a command to get the total disk space (available + free) on the solaris server ? thanks (3 Replies)
Discussion started by: sudhiroracle
3 Replies

6. Emergency UNIX and Linux Support

Calculating total space in GB for all files with typical pattern

Hi Experts, In a particular dir, I have many files *AJAY*. How can I get total size of all such files. I tried du -hs *AJAY* but it gave me individual size of all files. All I require is summation of all. Thanks, Ajay (4 Replies)
Discussion started by: ajaypatil_am
4 Replies

7. Solaris

Problem in getting total Disk space using iostat -En command

Hi Everyone, I try to calculate the total hard disk space of a solaris machine using iostat -En command. Iterating the output and summing up all the number present near the Size: will give the exact size of the harddisk. But it is not working for a machine. This command works in many flavors... (2 Replies)
Discussion started by: prasankn
2 Replies

8. Red Hat

Total storage space and Serial number

Hi, Could you please tell me the commands to find Total storage space and Serial number of Linux server. OS -- Red Hat Enterprise Linux Server release 6.6 (Santiago) This is 2 node cluster. Regards, Maddy (1 Reply)
Discussion started by: Maddy123
1 Replies

9. Shell Programming and Scripting

Calculate total memory using free -m

Hi I am trying to calculate memory used by Linux System free -m total used free shared buffers cached Mem: 32109 31010 1099 0 3600 7287 -/+ buffers/cache: 20121 11987 Swap: 10239 1282 8957 Now according to my requirement Im calculating memory using below cmd free -m | awk 'NR==3{printf... (2 Replies)
Discussion started by: sam@sam
2 Replies
MALLINFO(3)						     Linux Programmer's Manual						       MALLINFO(3)

NAME
mallinfo - obtain memory allocation information SYNOPSIS
#include <malloc.h> struct mallinfo mallinfo(void); DESCRIPTION
The mallinfo() function returns a copy of a structure containing information about memory allocations performed by malloc(3) and related functions. This structure is defined as follows: struct mallinfo { int arena; /* Non-mmapped space allocated (bytes) */ int ordblks; /* Number of free chunks */ int smblks; /* Number of free fastbin blocks */ int hblks; /* Number of mmapped regions */ int hblkhd; /* Space allocated in mmapped regions (bytes) */ int usmblks; /* Maximum total allocated space (bytes) */ int fsmblks; /* Space in freed fastbin blocks (bytes) */ int uordblks; /* Total allocated space (bytes) */ int fordblks; /* Total free space (bytes) */ int keepcost; /* Top-most, releasable space (bytes) */ }; The fields of the mallinfo structure contain the following information: arena The total amount of memory allocated by means other than mmap(2) (i.e., memory allocated on the heap). This figure includes both in-use blocks and blocks on the free list. ordblks The number of ordinary (i.e., non-fastbin) free blocks. smblks The number of fastbin free blocks (see mallopt(3)). hblks The number of blocks currently allocated using mmap(2). (See the discussion of M_MMAP_THRESHOLD in mallopt(3).) hblkhd The number of bytes in blocks currently allocated using mmap(2). usmblks The "highwater mark" for allocated space--that is, the maximum amount of space that was ever allocated. This field is maintained only in nonthreading environments. fsmblks The total number of bytes in fastbin free blocks. uordblks The total number of bytes used by in-use allocations. fordblks The total number of bytes in free blocks. keepcost The total amount of releasable free space at the top of the heap. This is the maximum number of bytes that could ideally (i.e., ignoring page alignment restrictions, and so on) be released by malloc_trim(3). CONFORMING TO
This function is not specified by POSIX or the C standards. A similar function exists on many System V derivatives, and was specified in the SVID. BUGS
Information is returned for only the main memory allocation area. Allocations in other arenas are excluded. See malloc_stats(3) and mal- loc_info(3) for alternatives that include information about other arenas. The fields of the mallinfo structure are typed as int. However, because some internal bookkeeping values may be of type long, the reported values may wrap around zero and thus be inaccurate. EXAMPLE
The program below employs mallinfo() to retrieve memory allocation statistics before and after allocating and freeing some blocks of mem- ory. The statistics are displayed on standard output. The first two command-line arguments specify the number and size of blocks to be allocated with malloc(3). The remaining three arguments specify which of the allocated blocks should be freed with free(3). These three arguments are optional, and specify (in order): the step size to be used in the loop that frees blocks (the default is 1, meaning free all blocks in the range); the ordinal position of the first block to be freed (default 0, meaning the first allocated block); and a number one greater than the ordinal position of the last block to be freed (default is one greater than the maximum block number). If these three arguments are omitted, then the defaults cause all allocated blocks to be freed. In the following example run of the program, 1000 allocations of 100 bytes are performed, and then every second allocated block is freed: $ ./a.out 1000 100 2 ============== Before allocating blocks ============== Total non-mmapped bytes (arena): 0 # of free chunks (ordblks): 1 # of free fastbin blocks (smblks): 0 # of mapped regions (hblks): 0 Bytes in mapped regions (hblkhd): 0 Max. total allocated space (usmblks): 0 Free bytes held in fastbins (fsmblks): 0 Total allocated space (uordblks): 0 Total free space (fordblks): 0 Topmost releasable block (keepcost): 0 ============== After allocating blocks ============== Total non-mmapped bytes (arena): 135168 # of free chunks (ordblks): 1 # of free fastbin blocks (smblks): 0 # of mapped regions (hblks): 0 Bytes in mapped regions (hblkhd): 0 Max. total allocated space (usmblks): 0 Free bytes held in fastbins (fsmblks): 0 Total allocated space (uordblks): 104000 Total free space (fordblks): 31168 Topmost releasable block (keepcost): 31168 ============== After freeing blocks ============== Total non-mmapped bytes (arena): 135168 # of free chunks (ordblks): 501 # of free fastbin blocks (smblks): 0 # of mapped regions (hblks): 0 Bytes in mapped regions (hblkhd): 0 Max. total allocated space (usmblks): 0 Free bytes held in fastbins (fsmblks): 0 Total allocated space (uordblks): 52000 Total free space (fordblks): 83168 Topmost releasable block (keepcost): 31168 Program source #include <malloc.h> #include "tlpi_hdr.h" static void display_mallinfo(void) { struct mallinfo mi; mi = mallinfo(); printf("Total non-mmapped bytes (arena): %d ", mi.arena); printf("# of free chunks (ordblks): %d ", mi.ordblks); printf("# of free fastbin blocks (smblks): %d ", mi.smblks); printf("# of mapped regions (hblks): %d ", mi.hblks); printf("Bytes in mapped regions (hblkhd): %d ", mi.hblkhd); printf("Max. total allocated space (usmblks): %d ", mi.usmblks); printf("Free bytes held in fastbins (fsmblks): %d ", mi.fsmblks); printf("Total allocated space (uordblks): %d ", mi.uordblks); printf("Total free space (fordblks): %d ", mi.fordblks); printf("Topmost releasable block (keepcost): %d ", mi.keepcost); } int main(int argc, char *argv[]) { #define MAX_ALLOCS 2000000 char *alloc[MAX_ALLOCS]; int numBlocks, j, freeBegin, freeEnd, freeStep; size_t blockSize; if (argc < 3 || strcmp(argv[1], "--help") == 0) usageErr("%s num-blocks block-size [free-step [start-free " "[end-free]]] ", argv[0]); numBlocks = atoi(argv[1]); blockSize = atoi(argv[2]); freeStep = (argc > 3) ? atoi(argv[3]) : 1; freeBegin = (argc > 4) ? atoi(argv[4]) : 0; freeEnd = (argc > 5) ? atoi(argv[5]) : numBlocks; printf("============== Before allocating blocks ============== "); display_mallinfo(); for (j = 0; j < numBlocks; j++) { if (numBlocks >= MAX_ALLOCS) fatal("Too many allocations"); alloc[j] = malloc(blockSize); if (alloc[j] == NULL) errExit("malloc"); } printf(" ============== After allocating blocks ============== "); display_mallinfo(); for (j = freeBegin; j < freeEnd; j += freeStep) free(alloc[j]); printf(" ============== After freeing blocks ============== "); display_mallinfo(); exit(EXIT_SUCCESS); } SEE ALSO
mmap(2), malloc(3), malloc_info(3), malloc_stats(3), malloc_trim(3), mallopt(3) COLOPHON
This page is part of release 3.44 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2012-05-06 MALLINFO(3)
All times are GMT -4. The time now is 08:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy