I have the find command as follows:

find /jobs/logs/* -prune -name '*.log' -type f -mtime +1 |
    while read LOGFILE
        echo $LOGFILE

This is failing due to the following error:

/usr/bin/find: arg list too long

Can anyone suggest a way to fix this?

(This is a continuation of my previous question.)


Let find to the directory traversal, that's its job! Building on my previous answer:

find /jobs/logs/. -name . -o -type d -prune -o
                  -type f -mtime +1 -exec sh -c 'echo "$0"' {} \;

Incidentally, note that I used -exec to make find invoke a command — that's what it's for.

Also, note that read LOGFILE does not read a line of input: it strips leading whitespace and interprets backslashes. A reliable way to read a line is IFS= read -r LOGFILE.


Try changing your find command to:

find /jobs/logs/. ! -name . -prune -name '*.log' -type f -mtime +1 

This tells find to exclude the . directory and prune all the rest, so that it doesn't descend further.

Take a look at this page for more information: Limit the search to the current directory portably

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.