-   Linux - General (
-   -   'find' gives different results when using -mtime with -print vs -exec (

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?

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

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

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

find . | wc -l

...and for the record:


find -version
find (GNU findutils) 4.4.0
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
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.:


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

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