Operating System - HP-UX
1758643 Members
2322 Online
108874 Solutions
New Discussion юеВ

"find -exec rm" command inconsistent response

 
SOLVED
Go to solution
Lonny Balderston
Frequent Advisor

"find -exec rm" command inconsistent response

Command in a script which runs on 6 similar HP9000s: " find /vz/data/prod/pipe_work -mtime +1 -exec rm {} \+ ". Response from command from only 1 of the six systems: " rm: /vz/data/prod/pipe_work directory ". Why is this? From the other 5 systems this command has no response at all. Thank you.
9 REPLIES 9
James R. Ferguson
Acclaimed Contributor

Re: "find -exec rm" command inconsistent response

Hi Lonny:

Define "similar" -- what release? What response that you expect aren't you getting?

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: "find -exec rm" command inconsistent response

Your question is far from clear. No response could simply mean no files were found; in fact, if the rm works as expected or no files match your filter, I would expect no output either to stdout or stderr. Only in the case where rm fails would I expect any output and then only to stderr.

While the "\+" is more effiecient than "\;", at least initially, I would replace it with "\;" and see if that improves the "no response" condition. I also suggest that you replace the "-exec rm {} \+" with something like "-exec ls -ls {} \;" so that it is very clear what arguments are supplied. Because you don't bother to identify your version of HP-UX, it's possible that you are running an old version with a smaller ARGMAX value so that the actual problem is that you are overflowing the argument list with your use of "\+". In any event, the more robust approach is to use the xargs command instead to aggregate the argument. You then have a controlled manner in which to group multiple arguments that prevents overflow.
If it ain't broke, I can fix that.
Victor Fridyev
Honored Contributor
Solution

Re: "find -exec rm" command inconsistent response

Hi,

Add <-type f> to find command:
#>find /vz/data/prod/pipe_wor -type f

HTH
Entities are not to be multiplied beyond necessity - RTFM
john korterman
Honored Contributor

Re: "find -exec rm" command inconsistent response

Hi,

on the sixth machine your rm command finds a directory, /vz/data/prod/pipe_work, which it cannot delete, therefore the message.
On the other five machine the rm command did not encounter any directories.
Go and check that /vz/data/prod/pipe_work is in fact a directory on machine no. six and try also to create a directory under /vz/data/prod on any of the other machines: you should then get the same response - after 24 hours.

regards,
John K.
it would be nice if you always got a second chance
Lonny Balderston
Frequent Advisor

Re: "find -exec rm" command inconsistent response

Thank you.

The 6 HP9000s are all HP-UX 11.11, with identical filesystems. The dir /vz/data/prod/pipe_work is a tmp dir for our application. The "-mtime +1 -exec rm" is intended to remove files over a day old. On 5 of the 6 systems, issuing the command " find /vz/data/prod/pipe_work -mtime +1 -exec rm {} \+ " results in a returned command prompt, i.e. no complaining from the OS. On the 6th system, the OS complains " rm: /vz/data/prod/pipe_work directory " - whether there are files to be removed or not. Dir /vz/data/prod/pipe_work exists and contains files on all 6 systems. Victor, the find -type suppresses the rm message, thanks. Still looking for the cause though.
James R. Ferguson
Acclaimed Contributor

Re: "find -exec rm" command inconsistent response

Hi Lonny:

The error is acutally self-explanatory.

"rm: /vz/data/prod/pipe_work directory"

...simply says that '/vz/data/prod/pip_work' is a *directory* and hence cannot be removed by 'rm'.

On the server wiht the "problem", an 'ls -ld /vz/data/prod/pipe_work' should show a directory that is older than 24-hours. On the servers that don't "complain" that directory should be *younger* than 24-hours old in terms of its last modification timestamp. Hence, on those servers, no attempt is being made to remove it.

Your 'find' command should look like:

# find /vz/data/prod/pipe_work -type f -mtime +1 -exec rm {} \+

...to limit the 'rm' to files and not files and directories. If you truly want to remove both files and directories, do:

# find /vz/data/prod/pipe_work -mtime +1 -exec rm -r {} \+

For better (much better) performance, use 'xargs' in lieu of '-exec', thusly:

# find /vz/data/prod/pipe_work -type f - time +1 | xargs rm

...This will collect groups of filenames as multiple arguments to 'rm' thereby spawning one process to remove many files at once instead of spawning one process to remove one file at a time --- a very expensive thing to do!

Regards!

...JRF...
Greg Vaidman
Respected Contributor

Re: "find -exec rm" command inconsistent response

James,

Your explanation of why the 6 systems are behaving differently is spot-on, as is your discussion of using xargs vs "\;" in a find command. But the usage Lonny is using with his find command is "\+" which behaves similarly to xargs, executing one command-line with all the "found" files as parameters. So xargs is the more common method to do this, but will not perform significantly differently than "find ... -exec rm {} \+"

--Greg
James R. Ferguson
Acclaimed Contributor

Re: "find -exec rm" command inconsistent response

Hi Greg:

Good point! You are of course correct. The plus sign in lieu of '\;' vastly improves performance by bundling multiple arguments. From habit, I use 'xargs' and tend to forget about the newer approach. Thanks for pointing that out.

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: "find -exec rm" command inconsistent response

However, the one downside is that "\+" has compared to the xargs approach is that xargs has the -L number argument which will prevent ARGMAX overflow. This shouldn't be a problem on later versions of HP-UX but if one is writing portable scripts that must work across many OS flavors then the xargs approach is the safer (andwiser) one.
If it ain't broke, I can fix that.