Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Or use a more appropriate tool for the job.' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Or use a more appropriate tool for the job.
Authored by: Sciandu on Sep 02, '06 10:35:32PM

Or you could just use a one-liner from the commandline.

To delete files:


find Downloads -mtime +14 | xargs -n 200 --replace={} rm {}

To list files:


find Downloads -mtime +14 -print

To move to trash:


find Downloads -mtime +14 | xargs -n 200 --replace={} mv {} ~/.Trash

To look for files older than 30 days, change the 14 to a 30. To look for files that have been modified in LESS THAN 30 days, change the + to a -. To find out more about what you can do with find, run "man find".

To make a shell script out of any of those, make a file that contains this line:


#!/bin/bash
Followed by one of the above lines, and where you see "Downloads", substitute in "$1". Save the file, do chmod +x filename, and you're off. The script will take the directory to operate on as a parameter.

No offense intended, but Ruby simply isn't the right tool for this particular job. It's an excellent language, and it excels in many areas but shell environments and the dozens of little utilities that support them were created precisely for handling these sorts of tasks and they do so very well with far less effort.

-JF

[ Reply to This | # ]
Or use a more appropriate tool for the job.
Authored by: spicyj on Sep 03, '06 10:36:25AM

Yes, but find is not restricted to only removing whole root level directories. That was my first solution, though.



[ Reply to This | # ]
Or use a more appropriate tool for the job.
Authored by: regeya on Sep 04, '06 01:38:44PM

Not sure *entirely* what you mean, but look in your find manpage for -maxdepth and -type. It may not be called -maxdepth in Tiger's 'find' (one of the bad things about 'standard' command-line utils is that they differ across platforms.) It may be necessary to do this in a couple of lines, which would mean a shellscript, but that's certainly OK.

I have a positively ancient OS 9.x/ASIP installation on which I boot an OS X boot CD once a month and run a shellscript that finds all files modified in the last month that are under 20MB in size, and then I ditto the files, delete the originals, and move the dittoed file into place. It takes very little time and really keeps file fragmentation down. It also made for a ridiculously small shellscript.

BTW, am I thinking right that the original Ruby script could be shortened extensively by using routines from rake?



[ Reply to This | # ]
Or use a more appropriate tool for the job.
Authored by: pinguru on Sep 06, '06 07:05:47AM

Any chance you could post the script? I have been tinkering with something like this for a while but to no avail (no shell scripting experience).

Cheers



[ Reply to This | # ]
Or use a more appropriate tool for the job.
Authored by: darsan on Sep 21, '06 10:56:34AM

I use the following command to clean out old home folders on multi-user workstations:

find /Users -maxdepth 1 -mindepth 1 -mtime +30 -type d ! -name Shared ! -name admin | xargs -n 100 rm -Rd

Change the -mtime option to + however many days you need, adjust the user directories you want to exclude at the ! -name options, for xargs it can be changed as needed. This makes a nice periodic launchd/cron script.



[ Reply to This | # ]