And how to delete files older 2 days? Get-Files / | select olderThan 2 | Delete-File ?
But it's not bash, it's coreutils
find ./ -mtime +2 | xargs rmBut it's not bash, it's coreutils
find ./ -mtime +2 | xargs rm 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?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.
/Mapped-Temp-folders/Server-Asia/temp
/Server-UK/temp
/Server-Japan/temp
I guess the script wouldn't work then if you wanted to clean out data older than 2 days, as per their timezone. ls|? LastWriteTime -lt (date).AddDays(-2)|rm