Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 12-08-2008, 10:27 AM   #1
Senior Member
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
'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?
Old 12-08-2008, 10:32 AM   #2
Senior Member
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
Find with -exec argument - not giving proper to find... hinetvenkat Linux - Server 4 01-25-2010 06:19 AM
find -exec syntax: bug in find? mfcarroll Programming 5 06-21-2007 07:13 PM
mtime in find vs ls lslade Linux - Software 0 11-17-2005 01:06 PM
Results of print job a nightmare loadedmind Linux - Hardware 4 01-04-2004 10:09 PM

All times are GMT -5. The time now is 10:07 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration