Edit script to not remove certain files
Hello all,
Google led me to a post by d3funct which is exactly what I needed but I need to modify it now. Code:
find /var/log -mtime +60 -type f -exec rm -rf {} \; How can I adapt it so that it only deletes files that are of type ".flv" - I can guess and test but that will mess things up ^^ - is it something to do with the "-name '*.flv'" option?? Thanks all :) |
This should do:
Quote:
|
Create a sandbox directory and experiment
-name "*.flv"
Add that to your find command. I do not understand why copying all the /var/logs into a sandbox (junk, play, experiment) directory will mess things up. Try things out there, and then implement the command in your "production" directory. |
Code:
This will delete files in the directory /var/log that are older than a day? Be very careful when using find with the option "exec rm -rf". This is especially important, because: - find is recursive: it will not only find the files meeting the conditions you set up in /var/log itself, but also in all sub directories. - "rm -rf" is recursive too: you will erase all concerned sub-directories and their content. So may I suggest you first write instead: Code:
find /var/log -daystart -maxdepth 0 -mtime +1 -type f -name "*.flv" Then and only then you can add "|xargs rm -f" (without the quotes) to your command.. |
Quote:
Thanks guys, this is the command I will use: Code:
find /var/log -mtime +60 -type f -name \*.flv -exec rm -rf {} \; |
Did you read my answer ? Remember the warning.
|
Quote:
Quote:
Quote:
Ok will check the above, the final command will be: Code:
find /var/log -daystart -maxdepth 0 -mtime +1 -type f -name "*.flv" |xargs rm -f Code:
-daystart Measure times (for -amin, -atime, -cmin, -ctime, -mmin, and -mtime) from the beginning of today rather than from 24 hours ago. Many thanks Didier. |
Quote:
|
I am using this in a cron job:
Code:
find /home/get/public_html/videos -daystart -maxdepth 0 -mtime +1 -type f -name "*.flv" |xargs rm -f Code:
find /home/get/public_html/videos -daystart -maxdepth 0 -mtime +1 -type f -name "*.flv" |
Are you running the cron job as the user that has enough permissions to delete the files from the directory.
|
[SOLVED]
Code:
find /home/get/public_html/videos -daystart -maxdepth 1 -mtime +1 -type f -name "*.flv" |xargs rm -f |
All times are GMT -5. The time now is 05:44 AM. |