Thursday | 21 NOV 2024
[ previous ]
[ next ]

Deleting Files Older than N Days

Title:
Date: 2024-01-08
Tags:  sysadmin

A handy little command to delete files. This is for Linux

find /path/to/folder -type f -mtime +30 -delete 

This will delete files older than 30 days in Windows. This also searches through subdirectories through the /s option. The echo is helpful to get some output of what was deleted.

forfiles /p "C:\Folder" /s /m *.log /D -30 /C "cmd /c echo @path && del @path"

forfiles documentation

Notice that the sign is different for the two operating systems. Annoying.