calculate internal fragmentation in directory

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support calculate internal fragmentation in directory
# 1  
Old 12-07-2011
calculate internal fragmentation in directory

hi

sorry for grammar mistakes but i am writting these fro tablet and am not realy used to ot so well yet....

i am in the middle of doing work here and hope some1 ca answear my question asap please :-)

How to calculate the amount of internal fragmentation using script.

cd directory ...
and???

whould i use du - s and number compare to moething oris there any command to calculate internal fragmentation?

thanks
# 2  
Old 12-07-2011
Definition I found with Google:
Internal Fragmentation is the term used to describe disk space which is allocated to a file but unused because the file is smaller than the allocated space.

As you again omit to mention what Operating System and version you have, and what Filesystem Type you have (e.g. UFS, VxFS , whatever) all answers can only be general.

Comparing the output from "du -s" with the total of the sizes of the files as reported by "ls -la" demonstrates the discrepancy.

Proprietary software may well provide better tools. Depends what you have.

It's a real problem on Windows systems with large discs and large numbers of small files. A disc upgrade can actually reduce the amount of free space!
# 3  
Old 12-07-2011
hey methyl and thanks foryouranswer

i know what internal fragmentation is i think i asked wrong way

what i meant was, how to write a script that will calculate in % how much dsck spaceistakingthat directory where script is executed

will appreciate help!

...filesystem is linux-opensuse ext3

---------- Post updated at 02:21 PM ---------- Previous update was at 02:08 PM ----------

if its stillnotclear i will write exactlyhowi got it...

write a script that will calculate amountof internal fragmentation forall files in directory. assume each block is1024 bytes
# 4  
Old 12-07-2011
Filesystem doesn't matter.

Just:

Code:
#!/bin/bash
DIR=/home/username
# du outputs "blocks folder" so we read both and just ignore the folder.
read USED_K FOLDER <<<$(du -s -B 1024 "$DIR" 2> /dev/null)
# du outputs a header line, then "filesystem blocks used available ..."
# so we ignore the header line with 'tail', then read the first three.
read FILESYSTEM TOTAL_K G <<<$(df -B 1024 "$DIR" | tail -n 1)
echo "$DIR uses $(( (USED_K*100) / TOTAL_K ))% of $FILESYSTEM"

Running this gets me
Code:
/home/username uses 51% of /dev/sdc5

---------- Post updated at 01:31 PM ---------- Previous update was at 01:27 PM ----------

Quote:
Originally Posted by me.
hey methyl and thanks foryouranswer

i know what internal fragmentation is i think i asked wrong way

what i meant was, how to write a script that will calculate in % how much dsck spaceistakingthat directory where script is executed

will appreciate help!

...filesystem is linux-opensuse ext3

---------- Post updated at 02:21 PM ---------- Previous update was at 02:08 PM ----------

if its stillnotclear i will write exactlyhowi got it...

write a script that will calculate amountof internal fragmentation forall files in directory. assume each block is1024 bytes
Which do you want? The space used, or something nebulous about fragmentation?
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 12-07-2011
doesnt matter now, I used the code you posted before and hope it will do so
BIG THANKS TO YOU !
# 6  
Old 12-07-2011
Quote:
Originally Posted by me.
doesnt matter now, I used the code you posted before and hope it will do so
BIG THANKS TO YOU !
It matters if you're doing anything with it... I don't understand why you'd stop caring when the time's up, unless this is homework.
# 7  
Old 12-08-2011
Ah, maybe the OP wants to know the amount of disk space used (blocks allocated * block size) versus the size of the files in bytes.
Code:
find . \( -type f -o -type d \) -printf "%b %s\n"  |awk '{ blocks+=$1; bytes+=$2; } END { print bytes/(blocks*BLKSZ)} ' BLKSZ=512

Gives me 0.997 for one directory, and 0.955 for another. Normally BLKSZ is 512, irrespective of the underlying filesystem's concept of a 'block'.

To be sure, just do
Code:
mkdir test; cd test;
find . -name . -printf "%b %s\n" | awk '{ print "Block size is " $2/$1 }'

One problem is that this doesn't account for hard-linked files, and therefore whose disk fragmentation would incorrectly be counted double.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to calculate average of all files in directory and output by part of filename

I am trying to use awk to calculate the average of all lines in $2 for every file in a directory. The below bash seems to do that, but I cannot figure out how to capture the string before the _ as the output file name and have it be tab-delimeted. Thank you :). Filenames in... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. IP Networking

IP fragmentation problem

Hello all, I am experiencing a problem with IP fragmentation. I am receiving an udp packet that is larger than the MTU and it is fragmented along the network. I am receiving the two fragments but they are not being reassembled correclty. The MTU of the system is 1500 and I cannot increase it,... (2 Replies)
Discussion started by: arichard
2 Replies

3. Shell Programming and Scripting

Find a particular directory in multiple file systems and calculate total size

Hello : I need some help in writing a ksh script which will find a particular directory in all the file systems in a server and finally report the total size of the direcotry in all the file systems. Some thing like this.. find /u*/app/oracle -type d -name "product" -prune and then... (1 Reply)
Discussion started by: Sam1974
1 Replies

4. Shell Programming and Scripting

How to calculate the entropy of a single directory that contains many files

Hello, I'm new member of shell scripting and i face some difficulties. To begin, i try to write an algorithm that calculate from one directory containing nfdump files (288) the entropy of one day 24hours. Each of the file is 5 min interval (nfdump -r nfcapd.200908250000 -s srcip) 1st (nfdump... (0 Replies)
Discussion started by: draxmas
0 Replies

5. UNIX for Advanced & Expert Users

Forwarding internal internet packets to internal webserver using iptables

Hi, I need to redirect internal internet requests to a auth client site siting on the gateway. Currently users that are authenticated to access the internet have there mac address listed in the FORWARD chain. All other users need to be redirected to a internal site for authentication. Can... (1 Reply)
Discussion started by: mshindo
1 Replies

6. UNIX for Dummies Questions & Answers

calculate directory size by year of file

I need to calcualte the size of a directory by the year the files in that directory were created . For example the script will sum up, by year, the number of blocks for that directory and its' subdirectories for files created / accessed in that year. I need a report that would look like... (11 Replies)
Discussion started by: igidttam
11 Replies

7. Solaris

Fragmentation Ratio

All. How can i calculate the fragmentation ratio on a mounted disk, given that i have no root privilege and i cannot switch to single user mode. (0 Replies)
Discussion started by: Negm
0 Replies

8. UNIX for Dummies Questions & Answers

Fragmentation command in linux?

Hi, Please let me know more details on fragmentation in redhat linux and command to check fragmented files? Thanks, Bache Gowda (2 Replies)
Discussion started by: bache_gowda
2 Replies

9. Shell Programming and Scripting

How to calculate file's size in directory and subdirectory

Hi, I have written one script to calculate total space of all file in one directory, ignoring subdirectory, it works fine. Now, I've been trying to calculate all files which includes files in any subdirectories. I use recursive function to do this, but it can work only if there is only one... (4 Replies)
Discussion started by: KLL
4 Replies

10. IP Networking

IP fragmentation

HI all, I am in urgent need of this answer. In TCP/IP protocol, If the IP datagram size > MTU of the any routing network then the IP fragmentation takes place! Where exactly the Fragmentation takes place? is it at the source network layer or in between at some router? If so, which of the... (1 Reply)
Discussion started by: reddyb
1 Replies
Login or Register to Ask a Question