LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   'find' gives different results when using -mtime with -print vs -exec (http://www.linuxquestions.org/questions/linux-general-1/%27find%27-gives-different-results-when-using-mtime-with-print-vs-exec-689123/)

BrianK 12-08-2008 10:27 AM

'find' gives different results when using -mtime with -print vs -exec
 
does anyone know why I'm getting different results here?
Code:

find . -mtime -2 -exec ls -lh '{}' \; | wc -l
7523

find . -mtime -2 -print | wc -l
332

... seems to me, they should be the same.

btw, the latter of the two is what I expect. What I'm going for is to find all files with an mtime of less than 2*24 hours (2 days).

If it means anything... in the same dir:
Code:

find . | wc -l
8132

...and for the record:

Code:

find -version
find (GNU findutils) 4.4.0
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Built using GNU gnulib version e5573b1bad88bfabcda181b9e0125fb0c52b7d3b
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS() CBO(level=0)


any ideas?

BrianK 12-08-2008 10:32 AM

For cryin' out loud. As soon as I posted the question, I thought, "I wonder if this could have anything to do with directories being listed" so I added "-type f" to the query & now we're back on track. I guess one of the things that was newer than 2*24 hours was a directory, "ls -lh" listed the whole directory along with all the other files that it found.

so, for anyone else with the same problem, be sure you're not listing subdirectories by locking in the type, i.e.:

Code:

find . -mtime -2 -type f -exec ls -lh '{}' \; | wc -l
331



All times are GMT -5. The time now is 11:27 PM.