LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-07-2005, 09:37 AM   #1
mem16421
LQ Newbie
 
Registered: Apr 2005
Location: Michigan
Distribution: SuSE 9.2 Pro
Posts: 7

Rep: Reputation: 0
Sort disk space by month?


I am in need of a script or program that can scan an entire drive and output a summary that lists space used by month. A script would be great since I would like to use it on several *nix platforms, and maybe Windows.

(example)

12/04: 200,153
01/05: 82,567
02/05: 1,986,123
03/05: 3,432,176
etc...

Thanks,

Mark
 
Old 04-07-2005, 12:50 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Welcome to LQ.

Do you mean you want to record it each month and display the usage of the previous months?

You could quite easily do this with the "df" command.
 
Old 04-07-2005, 02:12 PM   #3
mem16421
LQ Newbie
 
Registered: Apr 2005
Location: Michigan
Distribution: SuSE 9.2 Pro
Posts: 7

Original Poster
Rep: Reputation: 0
David,

I am looking for something that I can go up to a system at "anytime" and get a report of the space use by month. For example I could run this on a "Home Directory" tree and could see what month the users used the most space. Unfortunately I do not have the option of running a script every month to record history.

Mark
 
Old 04-07-2005, 02:17 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
If you don't record how much space is used monthly I'm not sure how you are going to have something to compare against.

You could get a usage for each directory and subdirectory on the system by running:
find / -type d -exec du -hs {} \;

It will take a while to run though. Obviously it will just search from the base of the find command so you can limit it to a specific area of the system.
 
Old 04-07-2005, 02:24 PM   #5
tommeke
LQ Newbie
 
Registered: Apr 2005
Location: Belgium
Distribution: Debian
Posts: 18

Rep: Reputation: 0
the `cron` system is made for running scripts on regular times or time intervals.

make script, probably something like
#!/bin/bash
df -h

(make it executable), test it
man cron : you'll get it running in no time!
 
Old 04-07-2005, 02:34 PM   #6
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally posted by tommeke
the `cron` system is made for running scripts on regular times or time intervals.

make script, probably something like
#!/bin/bash
df -h

(make it executable), test it
man cron : you'll get it running in no time!
And if you wanted you could have it log to a file to keep the results all in one place, even creating a script to parse the data in the log file to display month by month.. etc...
 
Old 04-07-2005, 06:38 PM   #7
mem16421
LQ Newbie
 
Registered: Apr 2005
Location: Michigan
Distribution: SuSE 9.2 Pro
Posts: 7

Original Poster
Rep: Reputation: 0
This is more difficult to explain than I though, but I appreciate the responses so far. First thing is that I don't want a running history of files by month, I want it do count the disk space consumed and sort it by month. For example lets say I have this directory:

-rw-r--r-- 1 mark users 1906 2004-12-29 06:42 file01.txt
-rw-r--r-- 1 mark users 560111 2004-12-06 18:20 file02.txt
-rw-r--r-- 1 mark users 472877 2005-01-09 07:31 file03.txt
-rw-r--r-- 1 mark users 444050 2005-01-09 07:30 file04.txt
-rw-r--r-- 1 mark users 444606 2005-01-09 07:31 file05.txt
-rw-r--r-- 1 mark users 744910 2005-01-06 18:20 file06.txt
-rw-r--r-- 1 mark users 2065188 2005-02-06 18:20 file07.txt
-rw-r--r-- 1 mark users 9049086 2005-02-13 15:33 file08.txt
-rw-r--r-- 1 mark users 229992 2005-02-09 07:30 file09.txt
-rw-r--r-- 1 mark users 364104 2005-03-06 18:20 file10.txt
-rw-r--r-- 1 mark users 809125 2005-03-23 19:08 file11.txt
-rw-r--r-- 1 mark users 463835 2005-03-17 20:49 file12.txt
-rw-r--r-- 1 mark users 214307 2005-04-06 18:20 file13.txt
-rw-r--r-- 1 mark users 498334 2005-04-06 18:20 file14.txt
-rw-r--r-- 1 mark users 6316 2005-04-11 17:37 file15.txt

I want a script/program that would run on a single or nested directories that would count the disk space consumed and then sort it by month. So my ideal output would look like this:

mark@linux:~/datesort .

Date Size
12-04 564017
01-05 2106443
02-05 11344266
03-05 1637064
04-05 718957

mark@linux:~/

So the 564017 is the total space consumed by files in 12-04 (file01.txt + file02.txt) If I ran this in the future I would not want it to compare any dates or files from before, I just want it to recount the files, and add the sizes up by date. This is a small sample but I could then use this data to say that the most disk space was consumed in 02-05. I think the tricky thing is that I need it to count disk space consumed by month for the entire directory tree that it is ran on, so it would need to add every directory up for a grand total at the end. I hope this helps, please don't give up I know there has to be a way to do this I just lack the time (and know-how) to figure it out.

Thanks,
Mark
 
Old 04-07-2005, 08:42 PM   #8
Kdr Kane
Member
 
Registered: Jan 2005
Distribution: SUSE, LFS
Posts: 357

Rep: Reputation: 30
Sounds like a backwards way of asking for disk quotas.
 
Old 04-08-2005, 04:58 AM   #9
mem16421
LQ Newbie
 
Registered: Apr 2005
Location: Michigan
Distribution: SuSE 9.2 Pro
Posts: 7

Original Poster
Rep: Reputation: 0
Except I am not tracking anything by user or directory.
 
Old 04-08-2005, 05:11 AM   #10
mem16421
LQ Newbie
 
Registered: Apr 2005
Location: Michigan
Distribution: SuSE 9.2 Pro
Posts: 7

Original Poster
Rep: Reputation: 0
Disk space by age?

I am trying to find the diskspace consumed by files older than 30days, 60days, 90days, and 180days, etc. I know that the find command can locate files by age, but since I want multiple ages and sizes I want to avoid running find (4) times. Is there a way to take output from ls and then run it through a script to get this data?

For example:

> ls -la / > output.out
> somescript < output.out

Age Space used
30 231MB
60 601MB
90 1031MB
180 2321MB

This way I only need to scan the entire tree once, and then run my script later or even on a different host.

Mark
 
Old 04-08-2005, 05:57 AM   #11
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Mark,
Since both of your threads were pretty much asking the same thing, I've merged them together.

Cheers.
 
Old 04-08-2005, 12:00 PM   #12
Kdr Kane
Member
 
Registered: Jan 2005
Distribution: SUSE, LFS
Posts: 357

Rep: Reputation: 30
Mark,

Some of the things you are asking for are done by a project called www.dirvish.org. Although, it's mostly for doing backups.
 
Old 04-08-2005, 02:26 PM   #13
mem16421
LQ Newbie
 
Registered: Apr 2005
Location: Michigan
Distribution: SuSE 9.2 Pro
Posts: 7

Original Poster
Rep: Reputation: 0
dirvish looks like a cool project to look into thanks! Also after reading the docs it does not look like it will just report without vaulting (backup) the data.
 
Old 04-09-2005, 09:31 AM   #14
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I haven't given it extensive testing but you could try this script - it jsut does the current directory but you could make it recursive:
Code:
#!/bin/bash

IFS="
"
for line in `ls -lt`;do
 if [ `echo $line | grep -c "^-"` -eq 1 ];then
  size=`echo $line | awk {'print $5'}`
  date=`echo $line | awk {'print $6'}`
  month=`echo $date | awk --field-separator "-" {'print $1"-"$2'}`
  if [ $lastmonth ] && [ "$lastmonth" != "$month" ];then
   echo $lastmonth = $total
   total=$size
  else
   total=$(($total+$size))
  fi
  lastmonth=$month
 fi
done
echo $month = $total
 
Old 04-09-2005, 12:25 PM   #15
mem16421
LQ Newbie
 
Registered: Apr 2005
Location: Michigan
Distribution: SuSE 9.2 Pro
Posts: 7

Original Poster
Rep: Reputation: 0
David,

Thanks!!!! This is a great help!!! I did add the -R to make it recursive but I end up with multiple same month totals. I think it count all the files in a directory on a certain month but when it starts another directory and the month is not the same it totals and then continues. I will then get a 2005-04 for the main directory and the subdirectoies. I have modified the script to read in a sorted ls output, but I haven't figured out a way to do this within the script. Any ideas?

Thanks again,
Mark
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't get Age of Empires II: Age of Kings started (I've could it before !!!) vegetassj2 Linux - Games 44 08-28-2005 04:59 PM
Disk Space Verbal Kint Linux - General 2 05-26-2005 06:28 PM
3Gb of disk space lost! Disk space problem or mother board conflicts with HDD Mistreated Linux - Hardware 4 12-06-2004 03:58 PM
Java does "age" or "Age" matter when declaring an Int?? Laptop2250 Programming 3 10-13-2003 12:34 PM
Disk space wastage 73 GB Hard disk rajgopalhg Linux - Hardware 2 10-18-2002 03:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration