[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 637
  • Last Modified:

Delete files older than 4 months old

I have a folder with thousands of sub-folders and files and I'm wanting to delete all the files and folders older than 4 months.

Is there an SSH command I can issue that would do this?
0
PeterErhard
Asked:
PeterErhard
3 Solutions
 
ExcelGuideConsultantCommented:
you should be able to find a couple of example here:
http://www.sitepoint.com/forums/showthread.php?t=602622

good luck
0
 
ozoCommented:
find /folder -mtime +120  -exec rm {} \;
0
 
woolmilkporcCommented:
Hi,
use "find" with its "-mtime" "option. Additionally use the "-depth" option to have find process the contents of a folder before the folder itself.
find /folder -depth -mtime +120 | xargs -I{} rm -r {}
To run it on a remote server using ssh simply do
ssh user@host  "find /folder -depth -mtime +120 | xargs -I{} rm -r {}"
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now