Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So i have a folder where i sometimes get few big files after doing some work.Problem is that every time i have to go and delete them manually.I know it's possible to delete them after 1 day or more but i would like to be able to delete them if they have been modified in the last few hours.

To further complicate matters there are other files in that folder that i do NOT want to delete and to complicate things even further they all have very similar yet unpredictable filenames.Meaning i cant just use del to delete the newest ones but i have to rely on modify date.

Can it be done in Win7?

share|improve this question
add comment

2 Answers

find /some/dir -type f -mmin -<minutes old> -print0 | xargs -0 rm

This finds all items under /some/dir that are files and are less than <minutes old> minutes old, and removes them. Don't forget the - before the number of minutes. Also, if mmin doesn't do the trick, try cmin.

share|improve this answer
    
If you're going to assume GNU find, this can be simplified to find /some/dir -type f -mmin -<minutes old> -delete. Run it first without the -delete option to show what it would delete. With POSIX find, find /some/dir -type f -mmin -<minutes old> -exec rm {} +. But this requires Unix utilities which are not bundled with Windows. –  Gilles Aug 21 '10 at 10:41
    
Doh. Did the 'windows 7' tag get added after I answered? I didn't see it if not. I wasn't aware of -delete. To be frank I'm not a fan of -delete and -exec arguments to find; they seem like bloatware, and the escaping that -exec always required offended my delicate sensibilities. Still, additional knowledge is good; Thank you. –  Slartibartfast Aug 22 '10 at 1:02
    
@slartibartfast: I added the Windows tag because the question body mentioned Windows. -exec is POSIX, whereas -print0 is not. (Mind, -mmin isn't POSIX either, so my objection wasn't justified.) Escaping find output for xargs is hard unless you have -print0; I like -exec ... + a lot better, and it doesn't require any escaping. –  Gilles Aug 22 '10 at 23:31
    
Personal preference. I just think find+xargs is more unix-y (in the philosophical sense, not POSIX/non-POSIX). I also recommend grep -Z and possibly tar --null. (Note also that xargs can do controlled parallelism with -P) –  Slartibartfast Aug 25 '10 at 1:42
add comment

IIRC the Windows Explorer can sort by modification time, so you could do that and select the files that were modified in the desired time range.

slartibartfast has given an answer that assumes you have Unix-like utilities installed. On Windows, this could be cygwin or GNU Win32 utilities or Microsoft Windows SFU or UWIN. If you install one of these, make sure to use its find and not the unrelated native Windows command.

share|improve this answer
    
I would first like to get this to work without installing any extra software and after im sure i can't be done i will try out some of the mentioned utilities. You said: "IIRC the Windows Explorer can sort by modification time, so you could do that and select the files that were modified in the desired time range." How do do this? –  TMRW Aug 21 '10 at 12:06
    
@TMRW: Open the directory in Explorer. Select “Details” in the “Display” menu (the name may be different in your version of Windows). Then click on the header of the date&time column to sort by date&time. –  Gilles Aug 21 '10 at 12:39
    
Yeah that's the manual way.I'm looking for an automated way via cmd. –  TMRW Aug 21 '10 at 14:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.