Aging file not use and touch

Hi all,

Need advice from expect, below is my scripts to find the file not use and touch in storage and other directory.

This scripts divide by:

  1. 30 days
  2. 90 days
  3. 180 days
  4. 1 years
  5. 3 years
  6. 5 years

Then count total size in GB from 6 each category.

Sample my scripts:

 
# 30 days
find /mnt/emage -type f -mtime -30 ! -mtime -0 -exec ls -la {} \; > 30days.txt
cat 30days.txt | awk '{ SUM += $5 } END { printf "30days,%.2f\n",SUM /1024^3 }' >> aging_temp.csv
 
# 90 days
find /mnt/emage -type f -mtime -90 ! -mtime -60 -exec ls -la {} \; > 90days.txt
cat 90days.txt | awk '{ SUM += $5 } END { printf "90days,%.2f\n",SUM /1024^3 }' >> aging_temp.csv
 
# 180 days
find /mnt/emage -type f -mtime -180 ! -mtime -150 -exec ls -la {} \; > 180days.txt
cat 180days.txt | awk '{ SUM += $5 } END { printf "180days,%.2f\n",SUM /1024^3 }' >> aging_temp.csv
 
# 1 Years
find /mnt/emage -type f -mtime -365 ! -mtime -335 -exec ls -la {} \; > 1years.txt
cat 1years.txt | awk '{ SUM += $5 } END { printf "1years,%.2f\n",SUM /1024^3 }' >> aging_temp.csv

 
# 3 Years
find /mnt/emage -type f -mtime -1095 ! -mtime -1005 -exec ls -la {} \; > 3years.txt
cat 3years.txt | awk '{ SUM += $5 } END { printf "3year,%.2f\n",SUM /1024^3 }' >> aging_temp.csv
 
# 5 years
find /mnt/emage -type f -mtime -1825 ! -mtime -1675 -exec ls -la {} \; > 5years.txt
cat 5yeras.txt | awk '{ SUM += $5 } END { printf "5year,%.2f\n",SUM /1024^3 }' >> aging_temp.csv
 
mv aging_temp.csv aging.csv

Thanks.

What is your question?

find /mnt/emage -type f \( -mtime -1825  -a -mtime +1675 \) -exec ls -la {} \;

Your syntax may want to change to the above as well. This example is:
less than 1825 days and greater than 175 days, using POSIX-compliant syntax for find.

Thanks Jim Mcnamara.

My question is just only need expert in this forum verify and comment my scripts. Maybe have better scripts other than this.

From your post:

find /mnt/emage -type f \( -mtime -1825  -a -mtime +1675 \) -exec ls -la {} \;

This scripts maybe I can put in as 5 years aging. I have question for +1675, how do you calculate and get this figure?. What I understand -1825 is equal to 5 years.

How about 30 days, 90days, 180days, 3years, 1years and 5 years already have it.

Thanks.

Another way to do it would be to loop through all the files something like this:

for f in $(find /mnt/emage -type f); do
    # examine and classify $f
done

This command will give you the file's age in seconds: date -r "$f" +%s

This command does the same: stat -c%Y "$f"

The current time in seconds: date +%s

The file's size in bytes: stat -c%s "$f"

You might be able to make a nicer script with the individual pieces.

Thanks KenJackson,

I'm not understand, so sorry. Can you explain me how to run this script? and guide me to this in detail?

Thanks again.

I didn't have time to write the script.
I just mentioned the commands that would be used to do it a different way.