Today's Posts

BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

disk space used for files with in a directory structure.

shell scripts

Login to Reply

Thread Tools Search this Thread
# 1  
Old 01-14-2005
disk space used for files with in a directory structure.

I am new to shell scripting and would really appreciate if someone could help me with this question.

I have a directory structure as follows..
main directory is DATA under which i have different directories names fileserver01, fileserver02 ... till fileserver 15.

under each of these there are more subdirectories named
123456, 123567,123984..... 234859,234503.. etc.

under each of these six digit subdirectory there are more subdirectories named subdir1, subdir2, subdir3... subdir7, which in turn contains individual files.

Now, my question is.. how can I find the disk space used by certain amount of files(not starting with "deleted") under subdir1,subdir3 and subdir4. also, the disk space should be based on the first three digits of the directories starting with eg..123, 234 etc.
ie. I need to find the diskspace of DATA/iterate thro' all fileservers/grouped under the matching first three digits eg 123*)/specified directories eg.subdir1,subdir3,subdir4)/(files not starting with "deleted").
I hope my question is clear.
I am using Ksh.

Thanks in advace.
# 2  
Old 01-14-2005
I am not quite sure what you are looking for, but du -sk is probably the command you want to use. Read the man page on du.
# 3  
Old 01-14-2005
I too am lost, but if you cd to fileserver1, you can do:
find 123* -type f
to get a list of files under the 123* directory. Is this a list of files that you want? Next you can do:
find 123* -type f | xargs ls -s
to see the files with their sizes. Just want a total? Use:
find 123* -type f | xargs -s | awk '{x+=$1} END {print x}'
Since -s is giving the size in blocks you might want to use "print x * 512" to get the size in bytes. This should be enough ideas to get you started.
# 4  
Old 01-14-2005
Sorry for the confusion which I created. I have two more twists to Perderabo's solution Under each 123* directory.. there are more subdirectories out of which I do not pick two particular subdirectories named subdir2 and subdir5. From the remaining subdirectories, I pick only those files whose names do not start with "deleted".
# 5  
Old 01-14-2005
find 12* -type f | xargs ls -s | egrep -v "subdir2|subdir5|deleted"
# 6  
Old 01-14-2005
If subdir2 and/or subdir5 are very large or if there are a lot of delete* files, this will slow down as it does work which is discarded by the grep processes. A complex find statement can produce a list of only the desired files...

find 123* \( -name subdir2 -o -name subdir5 -prune \) -o -type f ! -name delet\*
# 7  
Old 01-14-2005
Excellent Perderabo !
If a i add -prune after suddir2 to eliminate subdir2 files ????
Following did work for me on AIX.

find 1234* \( -name subdir2 -prune -o -name subdir5 -prune \) -o -type f ! -name delet\*
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Archiving files keeping the same structure directory csierra Shell Programming and Scripting 2 08-20-2013 12:52 AM
Extract files from tar ball without directory structure chetan.c Shell Programming and Scripting 4 05-02-2012 11:14 AM
Run SED for all index.jsp files across a directory structure. rajkdutta Shell Programming and Scripting 6 09-14-2010 11:50 PM
How to traverse directory structure and sum size of files? siegfried Shell Programming and Scripting 5 06-29-2010 05:41 AM
C++: how to check my directory disk space SamRoj Programming 2 04-20-2009 02:08 PM
Transfer files wih directory structure. uxlunatick SCO 11 04-28-2008 04:25 PM
copy files with directory structure adddy UNIX for Dummies Questions & Answers 3 12-11-2006 08:50 AM
MV files from one directory structure(multiple level) to other directory structure srmadab UNIX for Advanced & Expert Users 4 09-13-2006 05:01 PM
How do I increase disk space available to a directory? rhack UNIX for Dummies Questions & Answers 2 10-21-2005 12:54 PM

All times are GMT -4. The time now is 02:11 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
Show Password