Unix/Linux Go Back    


Shell Programming and Scripting 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 Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-14-2005   -   Original Discussion by kasala
kasala's Unix or Linux Image
kasala kasala is offline
Registered User
 
Join Date: Jan 2005
Last Activity: 1 July 2013, 1:34 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
disk space used for files with in a directory structure.

Hello,
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.
Sponsored Links
    #2  
Old Unix and Linux 01-14-2005   -   Original Discussion by kasala
98_1LE's Unix or Linux Image
98_1LE 98_1LE is offline Forum Advisor  
Registered User
 
Join Date: Dec 2000
Last Activity: 21 May 2012, 6:37 PM EDT
Location: Greater Dallas area
Posts: 405
Thanks: 0
Thanked 3 Times in 3 Posts
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.
Sponsored Links
    #3  
Old Unix and Linux 01-14-2005   -   Original Discussion by kasala
Perderabo's Unix or Linux Image
Perderabo Perderabo is offline Forum Advisor  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 26 February 2016, 12:31 PM EST
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 64
Thanked 471 Times in 271 Posts
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 Unix and Linux 01-14-2005   -   Original Discussion by kasala
kasala's Unix or Linux Image
kasala kasala is offline
Registered User
 
Join Date: Jan 2005
Last Activity: 1 July 2013, 1:34 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry for the confusion which I created. I have two more twists to Perderabo's solution Linux 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".
Sponsored Links
    #5  
Old Unix and Linux 01-14-2005   -   Original Discussion by kasala
bhargav's Unix or Linux Image
bhargav bhargav is offline Forum Advisor  
Registered User
 
Join Date: Sep 2004
Last Activity: 22 January 2016, 4:39 PM EST
Location: USA
Posts: 512
Thanks: 0
Thanked 2 Times in 2 Posts
find 12* -type f | xargs ls -s | egrep -v "subdir2|subdir5|deleted"
Sponsored Links
    #6  
Old Unix and Linux 01-14-2005   -   Original Discussion by kasala
Perderabo's Unix or Linux Image
Perderabo Perderabo is offline Forum Advisor  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 26 February 2016, 12:31 PM EST
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 64
Thanked 471 Times in 271 Posts
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\*
Sponsored Links
    #7  
Old Unix and Linux 01-14-2005   -   Original Discussion by kasala
bhargav's Unix or Linux Image
bhargav bhargav is offline Forum Advisor  
Registered User
 
Join Date: Sep 2004
Last Activity: 22 January 2016, 4:39 PM EST
Location: USA
Posts: 512
Thanks: 0
Thanked 2 Times in 2 Posts
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\*
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
C++: how to check my directory disk space SamRoj Programming 2 04-20-2009 02:08 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 06:12 AM.