1832941 Members
2671 Online
110048 Solutions
New Discussion

file removal command

 
DELIN YANG
Advisor

file removal command

I would like to prune our user directories of files that exceed a set limit ( ie, say no more than 50 files per user directory ). Preferably, the older files would be the ones being deleted. However, I do NOT want environmental files such as .profile and .cshrc to be deleted. Any ideas for commands/scripts that woudl accomplish this. Thanks in advance, Jonas
Buy low, sell high!
3 REPLIES 3
Kofi ARTHIABAH
Honored Contributor

Re: file removal command

Your best bet is the find command:

find /home -mtime +300 ! -name ".profile" ! -name ".sh_history" ! -name "on.and.on.and.on"... -exec ls -l {}\;

to preview and use the -exec rm {}\; construct to remove.

nothing wrong with me that a few lines of code cannot fix!
James R. Ferguson
Acclaimed Contributor

Re: file removal command

Hi:

I would think rather than abritrarly remove user's files by sheer number limits, you would want to remove (or MOVE elsewhere) files that haven't been accessed in some defined period of time. Consider, by way of example, only:

# find /mydir -atime +30 -exec rm {} \:

This would remove files from /mydir that haven't been accessed in 30-days. See the man page for 'find' for more options and examples.

...JRF...
Tim Nelson
Honored Contributor

Re: file removal command

what about using disk quota's to force the users to clean up their own messes ? We origionally had this problem with abusers in the /home filesystem and once disk quotas on were set the problem no longer existed and I do not have to baby sit anymore. Just an idea.