Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I wanted to see all files modified within the last 10 days and who owned them, so i entered the following to give me an idea how many results would be returned;

find . -maxdepth 1 -mtime -10

I then issued the command;

find . -maxdepth 1 -mtime -10 -exec ls -lh {} \;

Both commands give very different result, but i dont understand why, can someone explain what is going on and why they produce different results?

share|improve this question
1  
Either add -type f to list only files, or add -d to the ls command. Otherwise ls will list the directory contents again. –  Dubu Jun 17 at 13:05

1 Answer 1

up vote 4 down vote accepted

Because you don't use option -type f, find will return all folders and files. In second command, if a folder is found, command ls -lh will list its content, causing more result than first command.

$ find . -maxdepth 1 -mtime -10 | wc -l
63
$ find . -maxdepth 1 -mtime -10 -exec ls -lh {} \; | wc -l
313

You should use:

find . -maxdepth 1 -type f -mtime -10

find . -maxdepth 1 -type f -mtime -10 -exec ls -lh {} \;

to list files only.

share|improve this answer
    
what is 1 in end of second find? –  Babyy Jun 17 at 13:07
    
@Babyy: Sorry, mistyping. –  cuonglm Jun 17 at 13:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.