Deleting files older than 6 hours

Hi All,

I am using the below script to find all the files in a folder which are older than 6 hours and delete all those files, but some how I am not getting the required output.

find $HOME/Log -type f -name "*.log" -amin +360 -exec rm *.* {} \

can any one please check and let me know where I am doing wrong.

Thanks,Subhasri

find $HOME/Log -type f -name "*.log" -amin +360 -exec rm  {} \;

I think the *.* is unnecessary because the find already listed the names and passed to "exec" and you missed the ";"^_^.

It is always good to list the files first, before removing the files directly.

In addition to the above educated posts, please consider using "-mmin" (modified) rather than "-amin" (accessed) for the reference timestamp.

you also may want to use

 -ok rm {} \;

to be prompted on if you want to delete the files or not. As mentioned earlier, I suggest listing the files first (so run your command without executing 'rm') to make sure you're getting your desired output. Am I the only 'xargs' fan in the building? Everyone seems to like '-exec' but I find that to be SLOWER. Anyways just my stink on it.

Thanks for the replies.
I have modified the script instead of removing I am moving the files to archive location.
but when when I am executing I am getting the blow error

find /root/dun/ -type f -name "*.log" -amin +360 -exec mv \sune\dan\;
find: missing argument to `-exec'

And find is moving based on the system time.., do we have any command which will move the file to archive location based on file creation date.

Thanks,Subhasri

The 'mv' command

find /root/dun/ -type f -name "*.log" -amin +360 -exec mv \sune\dan\;
find: missing argument to `-exec'

needs to know where to move the file to. You need to specify a second location and you need {} braces afterwards so it can -exec on each file found.

Also for

mv \sune\dan\ don't you mean /sune/dan/

?

Hey I tried with braces.., but no luck

find /root/dun/ -type f -name "*.log" -amin +360 -exec mv {} \sune\dan\;

What's your error? Is \sune\dan a valid location? You need to escape the ";" at the end.

 find /root/dun -type f -name "*.log" -amin +360 -exec mv {} \sune\dan\ \;

Maybe try

 find /root/dun/ -type f -name "*.log" -amin +360 |  xargs mv -t \sune\dan\ \;

I'm an xargs fan instead of a -exec switch fan. Just personal preference

Hey I have tried with braces but ..it's not moving teh files

find /root/dun/ -type f -name "*.log" -amin +360 -exec mv {} \sune\dan\;

the command is working properly but I am not getting the required output

Ok, so A: \sune\dan is not a valid directory. /sune/dan would be valid. B: My last post should work fine if you give a valid directory. Run

 find /root/dun/ -type f -name "*.log" -amin +360 

and see if that finds your files. Then add on the rest. You need to give more information about what happens.

I am doing as below.

I did a pwd on my source directory it is showing as

/root/poc/

and I did a pwd on my target directory it is showing as

/sune/dan/

I executed the following code

find /root/poc/ -type f -name "*.log" -amin +360 | xargs mv -t sune\dan\ /;

I am getting the below error

mv: cannot stat `;': No such file or directory

and when I am executing

find /root/poc/ -type f -name "*.*" -amin +2

the command is listing the files as below

/root/poc/prakash.txt

some how mv is not happening.

Your solidus and reverse solidus characters are muddled. Also there needs to be a space character before \; at the end of the line:

Try:

find /root/dun/ -type f -name "*.log" -amin +360 -exec mv {} /sune/dan/ \;

Lol I showed him that in post #9 but he doesn't acknowledge either one of those answers and keeps flipping em back to \. I have asked a few times about the slashes and get no response.