How can i delete files in folder by date?

Hi,
I have some files on a folder and i want to delete all the files that were created on July.
Thanks,
Kobi.

Hi,

Copy and paste this when you have used 'cd' to change into the directory you want to work on:

ls -l | grep "[0-9][0-9] Jul" | awk ' {print $9}' | xargs rm -i

Note: this will go ahead and delete all those it found without confirmation to proceed, assuming the files you are wanting to delete have not been modified since they were created

Hi,
I tried it but it asks me for confirm the delete, and moves on to the next file...
I need it to delete everything on the folder that was created on july automaticaly without confirm.

kobibn,
miwinter suggested the 'rm -i' just so that you could choose to not delete files that you wanted to keep, but were selected by the grep command. If you are sure that all the files are to be deleted, skip the '-i' from the rm command.

Sorry, yes, I meant to add that, but after editing it to ensure you wouldn't delete files with Jul in the name of the file as well, I totally forgot to document that bit! Cheers BT

Thanks!!! Now i can really use it

My pleasure :wink:

Try this quick and dirty script, it will delete files with a modified date older than the value after "-mtime" in days (in this case 28 days) Obviously the cd needs to change to the folder you want to delete from

#!/bin/sh

#Delete all files Script for a Folder

#Change to folder to delete from
cd /YourPathtoFolder

for filename in $(find . -name "*" -mtime +28)
do
rm $filename
echo $filename "deleted"
done

Hi,
Does it work on Solaris 10???
10x.

Sorry Kobibn

I'm not sure if it will work on Solaris, but its a BASH script so I guess it should do

Try it and see