Find and delete

Hi Team,

The following command works fine in AIX 6.1.

find /home/abcd00 -name "*" -mtime +30 -print -exec rm -f {} \;

We are trying to implement a similar logic in Linux 2.6. But it is not working. Can anyone help us out?

Thanks
Krishna

It would have been very helpful if you were to explain in what way is not working for you in Linux. What did you expect and what did you not get.

Please, to troubleshoot, issue the command just as:

find /home/abcd00 -name "*" -mtime +30 -print

Look at the result and think if everything you are seeing is proper to delete.
Then, think about what that "*" means there, and if you think it would be necessary.

Problem statements like "But it is not working" do not really help, or how much would you appreciate an advice like "Modify the command"?
Please state clearly WHAT is going wrong and post relevant details like directory structure (i.e. does /home/abcd00 exist and contains files?) and OS version.

BTW: -name "*" is redundant - try without.

-name "" omits ".?" in some versions of find. But in any case there should be -type f or \! -type d to ensure there is no rm attempt on directories (that take extra time).

1 Like

When I try to execute it from script, the command works fine. But when I execute it directly from console, it is throwing the following error.

$ find /home/abcd00 -name "*.txt" -mtime +30 -exec rm -f {}
find: missing argument to `-exec'
$

Because you missed the ending \; ?