LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Disk space by age? (https://www.linuxquestions.org/questions/linux-software-2/disk-space-by-age-311014/)

mem16421 04-07-2005 09:37 AM

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

david_ross 04-07-2005 12:50 PM

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.

mem16421 04-07-2005 02:12 PM

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

david_ross 04-07-2005 02:17 PM

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.

tommeke 04-07-2005 02:24 PM

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!

trickykid 04-07-2005 02:34 PM

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...

mem16421 04-07-2005 06:38 PM

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

Kdr Kane 04-07-2005 08:42 PM

Sounds like a backwards way of asking for disk quotas.

mem16421 04-08-2005 04:58 AM

Except I am not tracking anything by user or directory.

mem16421 04-08-2005 05:11 AM

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

jtshaw 04-08-2005 05:57 AM

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

Cheers.

Kdr Kane 04-08-2005 12:00 PM

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.

mem16421 04-08-2005 02:26 PM

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.

david_ross 04-09-2005 09:31 AM

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


mem16421 04-09-2005 12:25 PM

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


All times are GMT -5. The time now is 01:06 PM.