Arg list too long error while using find
7,471
Solution 1
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
.
Solution 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
Related videos on Youtube
![Felix Ebert](https://i.stack.imgur.com/UShWX.jpg?s=256&g=1)
Author by
Felix Ebert
Updated on September 18, 2022Comments
-
Felix Ebert almost 2 years
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.)