3 ms·
Get-ChildItem -File | Where-Object LastWriteTime -lt (Get-Date).AddDays(-2) | Remove-Item If you prefer shorter (and similarly obscure if you don't know the la
by ygra 10y ago
Get-ChildItem -File | Where-Object LastWriteTime -lt (Get-Date).AddDays(-2) | Remove-Item
If you prefer shorter (and similarly obscure if you don't know the language):
ls -file|? LastWriteTime -lt ((date)+'-2')|rm
I actually find PowerShell's version more readable, even if more verbose. But code is written only once and read a lot of times. I may not know what the +2 actually means with the -mtime argument. How would I change it to look for the age of two hours instead of days?
- vasilia 10y ago> I actually find PowerShell's version more readable, even if more verbose. Sorry, I can't agree with you. > I may not know what the +2 actually means with the -mtime argument. How would I change it to look for the age of two hours instead of days? If you forget or doesn't know what is mtime, you can open man find. For less granularity than days use mmin.