First, you should explain to us. How did it not work? Show us the error messages. If there weren't any, then at least show us an example of the file hierarchy before running the command, after running the command, and how it should have been after running the command.
You say you "need to clean all days". What is a "day"? A directory? A file? Again, show us a sample of the filesystem hiearchy.
Is everything to be deleted in a single directory, or will find descend into subdirectories? If it will descend, will you be deleting only files, only directories, or both? Depending on the exact nature of the task, a depth-first traversal may be necessary. Again, a better explanation of what's going on is required.
Why are you using -name '*' ? That will always evaluate to true. It's redundant.
thanks for your replies. So i need to give more explications sorry.
the command :
find /usr/IBM/HTTPServer/apache_cache/ -type f -mtime +1 -exec rm {} \;
is ok i used it before but our Customer said us to use xargs because it's more efficient and quicker.
Yes it is necessary to clean all days so the rule is just to keep one day
The hiearchy is :
drwx------ 3 nobody nobody 4096 May 26 10:53 RWn
drwx------ 3 nobody nobody 4096 Jan 27 19:00 T0t
drwx------ 3 nobody nobody 4096 May 26 13:19 T6Q
drwx------ 3 nobody nobody 4096 Jan 27 19:00 TKg
drwx------ 3 nobody nobody 4096 Jan 27 19:00 UTN
in the directory UTN (per example) are others directories and files that must be clear if there are older than one day. Sometimes the directories could be must spaces.
Your original post uses find -print0 and xargs -0. Is your customer using a GNU userland? If not, those extensions are probably not supported. If they are using a GNU userland and if that's all that needs to be supported, then Don Cragun already gave you the answer.
Why is your customer dictating to you how to solve a problem? I'm inclined to think that they should dismiss you if they know more than you.
attempts to remove directories and all of their contents and then to remove some of the files in those directories after they have already been removed while removing their parent directory recursively. Furthermore, if a directory hasn't changed in a day, but files in one or more of it subdirectories changed in the last hour, those directories and the new files in them will also be removed.
A safer way to do it would be a two step process: remove the old regular files in the 1st step and then remove old directories in the 2nd step:
Using rmdir instead of rm -r guarantees that you won't remove new files accidentally, but you might get error messages trying to remove directories that aren't empty. If that is a concern, you could redirect stderr from the 2nd find . This method will keep directories that have been emptied by the 1st find around for an extra day (since the directory timestamps will be updated when the regular files in them are removed), but they will be cleaned up one day later if they are then empty.
No, it isn't. If no filenames were passed through the pipe to xargs , xargs should not exec rm . Something else is going on here, but it isn't clear to me what.
Interesting. The standards don't include the -print0 primary for find nor the -0 option for xargs . But, in a directory with the following files:
file
problem
test
tester
The following session using ksh on Mac OS X:
$ find . -name 'nothing' -print0 |xargs -0 echo xx
$ find . -name 'nothing' |xargs echo xx
$ find . -name '*r' |xargs echo xx
xx ./tester
$ find . -name '*r' -print0 |xargs -0 echo xx
xx ./tester
$
shows the behavior required by the standards when -print0 and -0 are not used (i.e., no files read by xargs from stdin; no invocations of the specified command). I don't see any reason why the behavior should be different when those options are used; and, at least on Mac OS X, the behavior is the same.