4 ms·
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 rm
by vasilia 10y ago
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 rm
- ygra 10y agoGet-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.
- useerup 10y agols|? LastWriteTime -lt (date).AddDays(-2)|rm
- ksk 10y agoJust as an aside (and this probably applies to powershell as well), what if you have mapped folders from multiple servers into your file system and those servers are in different timezones? Something like /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.