Capacity of directory... Pulling hair out :-)

I am new to scripting and thought I was doing rather well however I ran into a issue and I am not sure how to fix it. I am using the following command to obtain the capacity percent of the directory listed however it seems that this command gets the capacity of the whole mount rather then just the directory specified.

df -bhk /lcl/prd/data/sm2p/archives | cut -d "y" -f1 | awk '{print$5}'

81%

I only want toe capacity of archives and not the capacity of the whole mount. The folder archives is empty yet it comes back with 81% because its looking at the whole mount.

Am I using the wrong command (df)? I am not sure how to obtain what I want here.

Thanks in advance for the help.

You are asking the system a question for which there is no sensible answer. Free space is by FILESYSTEM, not directory. If the filesystem mountpoint is the directory, then free space is for the directory (which == filesystem) and all of its children.

You can ask are there any files in the directory, or how many bytes are used by the files in the directory. Then

 100 * (bytes used/bytes in filesystem) 

gives an approximate answer. This doesn't take into account the fact that files are uusally mapped onto a minimum allocated disk space. For example, a 1 byte file actually uses say 1024 bytes, and a 480 byte file is also stored in a 1024 byte parking place.

480 + 1 = 481 but the actual used space is really 2048 - in this example.

Sounds like you need 'du' instead of 'df' but it's going to give you the size of a file/directory not percentages.

Is there a way to convert that to percentages?
I am not concerned with the sizes of the folders leading up to the one I want to monitor. I only want the percentage full of the archives folder.

Thanks again for the help.

---------- Post updated at 08:09 AM ---------- Previous update was at 07:06 AM ----------

I see how to use the du... for example....

du -s /lcl/prd/data/sm2p/archives | cut -f1

But I still do not understand how to figure out the capacity of the folder from the return or how to take that and turn it into a percentage.

The format of "df" varies across platforms. Please state you Operating System and preferred shell.
Ignoring unix quotas (rarely ever used).the maximum total size of the files in a
directory equates to the available free space in that mountpoint.

But I still do not understand how to figure out the capacity of the folder from the return or how to take that and turn it into a percentage.

As Jim Mcnamara there is no concept of "capacity of a folder" in Unix or GNU/Linux. For starters Unix and GNU/Linux has directories not folders. And unlike Windows/DOS FAT12 or FAT16 there is no inherent limitation on the number of files in a directory. Unless you are using quotas (and generally only large organizations use quotas) the best you can do is determine the capacity of the filesystem on which the directory resides and the amount of free or allocated space on that filesystem.

So I want to make sure I am understanding this correctly....
There is no way to monitor only the size of the directory?
We have file systems that may have a few directories within them that belong to different groups so I want to be able to monitor the directories independantley. So for example if I have 3 directories....

Directory 1 Belongs to Group A
Directory 2 belongs to Group B
Directory 3 belongs to Group C

If Directory 2 fills beyond 80% of its capacity I do not want Group A and C to have to check their directories when we know its not theirs thats filling things up.

Also the OS is Solaris 10 and shell is ksh.

How are you going to determine what the capacility of directory 2 is?

Ok just got a leason on mountpoints. Now I see why this was not working. :slight_smile: What can I say.... I come from the Windows world.

Thanks for the help.