1825805 Members
2110 Online
109687 Solutions
New Discussion

Re: File census

 
SOLVED
Go to solution
Donald Thaler
Super Advisor

File census

I have inherited two hp unix servers that have files that are "older than the hills" and I would like to prune them from the tree. Does anyone have any scripts that will go thru and list out files by date and or by size.
4 REPLIES 4
Chan 007
Honored Contributor

Re: File census

Don,

use

find / -mtime <720=days old> -exec rm {} \;

starts form /

if specific
then
find /don -mtime 720 -exec rm {} \;

use mtime for modified time and
atime for access time.


Chan
James R. Ferguson
Acclaimed Contributor
Solution

Re: File census

Hi Donald:

'find' is your friend for this. See its manpages for more details.

# find /path -xdev -type f -mtime +120 | xargs ls -l

...will search /path not cross any mountpoints (-xdev), look only for files (-type f) that have not been modified in 120-days or more (-mtime +120) and pipe any of the names found to 'ls -l' to offer you a full long-listing.

You can change the 'ls -l' to 'rm' if you are satisfied that you want to remove all of those candidates.

# find /path -xdev -type f -mtime +120 | xargs ls -l

Similarly, to find all files whose size is greater than 100,000 characters, do:

# find /tmp -xdev -type f -size +100000c | xargs ls -l

Regards!

...JRF...


Chan 007
Honored Contributor

Re: File census

Don,

Sorry my 1st one will remove all.

use

find / -mtime +720 -print

the above will print files more than 720 days old.

find you want that in a file

then
find / -mtime +720 -print >> /tmp/720days_files


find / -size +nk 2000 -print
prints size more that 2M

Chan
Muthukumar_5
Honored Contributor

Re: File census

For listing by date,

# find / -type f -mtime +45 -exec ls -l {} \;

It will list files who are elder that 45 days.

Based on size,

# find / -type f -exec du {} \; | xargs sort -rnk 1

--
Muthu
Easy to suggest when don't know about the problem!