Finding size of all directories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Finding size of all directories
# 1  
Old 06-28-2011
Question Finding size of all directories

Alright so I've tried a couple different things that at first glance, looked like they worked.


Code:
find . -maxdepth 5 -type d -daystart -mtime 1 | xargs du -h

Which seems to ignore the previous commands such as depth and modified time.

Code:
find ..  -maxdepth 2 -type d -daystart -ctime 1 | xargs ls -dsh

Which appears to adhere to maxdepth and modified time, however gives an incorrect directory size..
Output:
Code:
8.0K ..
8.0K ../scripting/Final_Testing
8.0K ../scripting/Prelim_Testing


What I actually want, is to check to see if files in a directory have been modified, and then list the directory name and file size associated with it.

I'm very tired today, and I feel a fresh pair of eyes may help, thanks in advance
Michael

Last edited by Aussiemick; 06-28-2011 at 12:50 AM..
# 2  
Old 06-28-2011
I'll give it a shot Smilie
Code:
find "$PWD" -type f -daystart  -mtime -1 -exec du -sk {} \; | \
sed -e "s#\(/.*/\)#&\t#g" -e "s# #_#g" | \
awk '{a[$(NF-1)]=a[$(NF -1)] +$1 } {b[$(NF-1)]=b[$(NF -1)] $NF" "} END {for (i in a) print "DIR "i,"INCREASED SIZE FOR " a[i]/1024"MB","DELTA FILES : "b[i] } '

$PWD is starting dir, we need absolute paths.
Used du -sk for numeric in KB.
-type f instead of -type d you used.
If files in directory have spaces they are represented as _ instead of <space>.
I'm sure it has bugs Smilie

Regards
Peasant.
# 3  
Old 06-28-2011
Quote:
What I actually want, is to check to see if files in a directory have been modified, and then list the directory name and file size associated with it.
Please re-phrase the question avoiding the ambiguous "it" and give a detailed example of source data and expected output where the figures are correct. Please make the required units (blocks, kilobytes, whatever) clear.

Hmm. What is "file size associated with it"?
# 4  
Old 06-28-2011
Oh sorry, so I don't want individual files to be recorded, I only want the size of the folder.

But using ls, most folders return a size of like 8kb, whereas I know matter of factly I have hundreds of MB in some folders.


The output ideally would look something like
Code:
134M .
12M ./folder1
4M ./folder1/1
8M ./folder1/2
8KB ./folder2
1MB ./folder3


Something like that, with total filesize WITHIN the folder, not the files themselves

The idea behind this is that I can then export these to a csv file, open it in excel and create a % of growth formula to be used daily and track where the biggest changes in data occur
# 5  
Old 06-28-2011
The output from say "ls -lad" on a directory is the size of the directory file itself (how much space it takes to hold a list of files, properties, permissions and location on disc).

I don't have your version of "find" and cannot verify "-daystart" but I can see that the "-mtime" operator needs to be relative (-mtime -1) rather than absolute (-mtime 1). There is much variation in the syntax and behaviour of the "find" command. Try it on your system.

For example:
Code:
find . -maxdepth 5 -type d -mtime -1 | xargs du -sh

This User Gave Thanks to methyl For This Post:
# 6  
Old 06-28-2011
daystart
Finding size of all directories-daystartpng



I have a few different outputs for mtime, I don't overly understand the difference between 1 and -1 though

Finding size of all directories-sspng
Finding size of all directories-daystartpng
Finding size of all directories-sspng
# 7  
Old 06-28-2011
I honestly thought the idea of daystart was to start mtime from like, 12am, but that command was sorta thrown at me, so I just used it.

Also from the above image, I honestly can't tell what mtime 1 is showing me, although mtime-1 and 0 both seem to show what I did yesterday

---
I need more sleep, my brain is fried, working on little sleep != good
I'll try have another look later, thanks for all your help

---
Quote:
Originally Posted by Peasant
I'll give it a shot Smilie
Code:
find "$PWD" -type f -daystart -mtime -1 -exec du -sk {} \; | \
sed -e "s#\(/.*/\)#&\t#g" -e "s# #_#g" | \
awk '{a[$(NF-1)]=a[$(NF -1)] +$1 } {b[$(NF-1)]=b[$(NF -1)] $NF" "} END {for (i in a) print "DIR "i,"INCREASED SIZE FOR " a[i]/1024"MB","DELTA FILES : "b } '

$PWD is starting dir, we need absolute paths.
Used du -sk for numeric in KB.
[i]-type f instead of -type d you used.
If files in directory have spaces they are represented as _ instead of <space>.
I'm sure it has bugs Smilie

Regards
Peasant.
Interesting looking code, I ran it and had no bugs, I really don't understand awk or sed but that's purely because I haven't had enough experience with them, are you able to explain your code at all?

Last edited by Aussiemick; 06-28-2011 at 09:01 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding directories with expression

Hi All, I need your help in finding pattern of directories. need to search for all pattern have "mypatern" from base directory folder. example ------- server1 - base directory 100 server1/ab_123456_1/mypattern 100 server1/ab_123456_2/mypattern 200 server1/ab_123457_1/mypattern... (13 Replies)
Discussion started by: lxdorney
13 Replies

2. UNIX for Dummies Questions & Answers

Finding multiply directories

I have multiply directories scattered throughout my system that end in 2011. Example: one_2011 two_2011 three_2011 etc.... I'm trying to find all of these directories but coming up short. I tried find / -type d -name *2011 > example Any suggestions? I already searched in the... (13 Replies)
Discussion started by: shorty
13 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Finding the Files In the Same Name Directories

Hi, In the Unix Box, I have a situation, where there is folder name called "Projects" and in that i have 20 Folders S1,S2,S3...S20. In each of the Folders S1,S2,S3,...S20 , there is a same name folder named "MP". So Now, I want to get all the files in all the "MP" Folders and write all those... (6 Replies)
Discussion started by: Siva Sankar
6 Replies

4. Shell Programming and Scripting

How to list all the directories, sub directories in a mount along with size in ascending order?

Hi , I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In a particular mount, have to list all the directories and sub directories along with size of the directory and sub directory in ascending order. Please help me in this regard and many... (4 Replies)
Discussion started by: nmakkena
4 Replies

5. Shell Programming and Scripting

Finding directories older than 5 days

Hello, Motive: Search all directories which are older than 5 days. Example: consider following directory structure: abc/dir1 abc/dir1/dir abc/dir2 abc/dir3 abc/dir3/temp Suppose dir1 and dir3 are 5 days older. Then I am looking for a command which lists abc/dir1 and abic/dir3 only so that... (4 Replies)
Discussion started by: mytempid07
4 Replies

6. Shell Programming and Scripting

Finding directory and sub-directories individual size in Perl

Hi, Can anyone redirect to an existing thread or provide some info on how to find the size of a directory and it's sub-directories using a single script ? I tried finding a similar thread but in vain. I'm a newbie and any help would be greatly appreciated. Thanks in advance. (3 Replies)
Discussion started by: ryder
3 Replies

7. Shell Programming and Scripting

Script for parsing directories one level and finding directories older than n days

Hello all, Here's the deal...I have one directory with many subdirs and files. What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file. A script for... (5 Replies)
Discussion started by: ejianu
5 Replies

8. Shell Programming and Scripting

finding correct directories

I have directories like V00R01,V00R02,V01R01,V01R02 in a directory where V is version and R is a release. basically I need to set base directory and current directory. Under a version there can be any number of releases and there can be number of versions also. V00R01...V00R50..so on also,... (2 Replies)
Discussion started by: vjasai
2 Replies

9. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies

10. UNIX for Dummies Questions & Answers

finding directories in UNIX

I am accessing a UNIX server via FTP. I want to retieve a file in a directory. What is the UNIX command that I need to view and retrieve files from a directory? (1 Reply)
Discussion started by: yodaddy
1 Replies
Login or Register to Ask a Question