The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
get file size by date for a directory ibaboomer Shell Programming and Scripting 1 09-15-2009 09:04 AM
command to reduce size of file/directory??? nsharath Shell Programming and Scripting 2 01-21-2009 12:11 PM
How to compare size of two file which is in one directory Aditya.Gurgaon Shell Programming and Scripting 1 01-08-2009 06:28 AM
checking directory size in the text file G.K.K Shell Programming and Scripting 5 09-25-2008 11:23 AM
How to know size of file in a directory kittusri9 Shell Programming and Scripting 1 04-28-2008 09:43 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-13-2009
WorkOfArt WorkOfArt is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 1
Nominated Post Size of file and directory

Hello. I do have a problem.
The statement sounds like this: Given a directory, find all subdirectories (regardless of depth) which contain a file that has more than a half of the size of the respective subdirectory.

I've tried to solve this in many ways, but all I came up with is half solutions.

One would be trying this:

Code:
find folder -type f -size +x

where I would search for the size of each file, x being a variable, but this should be applied to each file.

Another one, which seems not to work, would be this:


Code:
for i in $(ls $1); do 
if [ -d $i ]; then 
echo $i; 
fi; 
done

but still, i should search for each file and compare it with the directory.

trying

Code:
ls -R folder

would be a solution, but I can't connect it with another command.

or this one:

Code:
for i in `find $1 type -d'
do
        for j in `find $i type -f -size +(size($i))` // in blocks
         do
                echo j;
         done
done

where, size($i) would be the size converted in blocks, and I didn't know how to do that.

Thanks

Last edited by WorkOfArt; 10-13-2009 at 09:23 AM..
Bits Awarded / Charged to WorkOfArt for this Post
Date User Comment Amount
10-13-2009 thegeek Good to see that what he have tried to achieve the solution 500
  #2 (permalink)  
Old 10-13-2009
thegeek thegeek is offline
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 463
It is great to see your question, i would greatly appreciate it.

Here is the answer for you.

Code:
ls -lh
total 28K
-rw------- 1 thegeek learner  18K Oct 10 05:52 feed
-rw------- 1 thegeek learner 2.5K Oct 10 05:51 feedbacks
-rw------- 1 thegeek learner   32 Oct 10 05:51 tttt

So only the feed is the file whose size is 18k which is more than the half of the dir size which is 28K.

To get that, following is the script.,

Code:
for i in `find . -type d`
do 
    echo $i
    dirsize=`du -s $i | cut -f1`
    echo $dirsize
    find $i -size +$dirsize -type f
done

If it requires a little edit for your requirement, go a head and do it. But this would help you in achieving the core part of what you would want.
Reply

Bookmarks

Tags
files, folders, ls, shell

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0