Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have the find command as follows:

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

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.)

share|improve this question
add comment

2 Answers 2

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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