LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 12-08-2008, 10:27 AM   #1
BrianK
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?
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?
 
Old 12-08-2008, 10:32 AM   #2
BrianK
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.:

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


Reply



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 output..how 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

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:34 PM.

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