Nelmo
Nelmo

Reputation: 215

unix find command with mtime - unexpected result

Sorry, annoying little question which no-one in my office seems able to answer...

The following command on our Linux system (ksh):

find . -mtime -3 -exec ls -lrt {} \;

...I would expect to list all files modified less than 3 days ago.

However, what I am getting is a list of all files in the current directory PLUS extra entries at the bottom for the 2 files (names made up, full details omitted for clarity) that are actually less than 3 days old ie.

...
fred.txt
john.sh
./fred.txt
./john.sh

I've tried using '-execdir' but makes no difference. Any ideas why this is?

Upvotes: 1

Views: 3617

Answers (1)

Christopher Neylan
Christopher Neylan

Reputation: 8272

Your find is finding the current directory. I.e.,

$ find . -mtime -3
.
$

Which means find is doing an ls -lrt ., which prints everything.

Upvotes: 1

Related Questions