when I run the following command in AIX (bash),
find ./*
I get the following error.
find: bad status-- ./*
Thats becasuse, its an empty directory. The same works, when there the directory is not empty. Even though the find deesnt have to rerun any result.
My full find command would look something like below.
find <dir>/* -type f \( ! -name '*.extn1' -a ! -name '*.extn2' \) -mtime +45 -exec rm -f {} \;
I form the above find command during the script run time.
But for simplicity sake, I had given just the simple fine command in the example.
How to get it fixed?
Thanks
Just give it the directory as an argument; not all of the files in the directory as separate arguments. I.e., change:
find <dir>/* -type f \( ! -name '*.extn1' -a ! -name '*.extn2' \) -mtime +45 -exec rm -f {} \;
to:
find <dir> -type f \( ! -name '*.extn1' -a ! -name '*.extn2' \) -mtime +45 -exec rm -f {} \;
and, you can get the same results with:
find <dir> -type f ! -name '*.extn[12]' -mtime +45 -exec rm -f {} \;
and, it will run a LOT faster if you use -exec command initial-args {} + to minimize the number of times you invoke rm :
find <dir> -type f ! -name '*.extn[12]' -mtime +45 -exec rm -f {} +
Thanks for your time and effort Don!!
As I mentioned, I form the find command based on parameter. So there will be a separate parameter for Directory and a separate param for File names.
eg:
find #DirName##Pattern#
So the pattern sometimes be "" or sometime be ".csv". Should I manually check for "*" and make it blank? Or is there any other options available?
Thanks for simplifying the extension expressions.
I just mentioned it for an example.
The actual value is
-type f \( ! -name '*.fs' -a ! -name '*.ds' \)
Iam going to try the below now. Thanks for the Suggestions!
-exec rm -f {} +
May I know the difference between
-exec rm -f {} + vs -exec rm -f {} \;
The + collects arguments (up to a certain limit) and runs one (or few) rm -f arg1 arg2 ... ,
while the ; each time runs the program with one argument rm -f arg1; rm -f arg2; ... .
Thanks for the Clarification!