Solved help with /usr/bin/find

Greetings,
I'm completely lost here and would appreciate any help.

I'm trying to understand the difference between "GNU find" and "BSD find," specifically how exactly primary -exec works.
I'm doing something like:
find . -mtime -2 -exec ls -l {} \;

So, the idea here is to display files that were modified less than two days ago, and then I'm replacing ls -l with a different tool that accepts exactly one argument as a file path.

While this works in Linux, FreeBSD's find gives me a complete list of all files in the current directory, ignoring primary -mtime -2.

I'm reading the "find" manual now to figure it out, but without avail yet.
Thanks
 
find . -mtime -2 -exec ls -l {} \;
So, the idea here is to display files that were modified less than two days ago,
[...]
FreeBSD's find gives me a complete list of all files in the current directory, ignoring primary -mtime -2.

Are you sure it's ignoring -mtime -2? Your command gives you all files and directories that were modified less than two days ago, including directories containing the files you actually modified.

When these directories are passed to ls, all their content is listed including files which weren't modified.

This should work:
find . -type f -mtime -2 -exec ls -l {} \;
 
Thanks!

I've actually found the issue just now. This is not related to "find" at all.

Since I'm not specifying primary "-type f" the find tool returns everything, including current directory.

Looks like BSD's /bin/ls follows recursion when dod (current directory) is specified; that's why I'm getting the whole content of the current folder.

So, just to make it clear, here's the difference example between FreeBSD and Linux with the same directories/files structure:
Code:
# FreeBSD
$ /bin/ls -l . | head -n 1
total 1260060

# Linux
$ /bin/ls -l .
total 0

Best
 
So, just to make it clear, here's the difference example between FreeBSD and Linux with the same directories/files structure:
Code:
# FreeBSD
$ /bin/ls -l . | head -n 1
total 1260060

# Linux
$ /bin/ls -l .
total 0

Best

That isn't OS dependent, it is filesystem type dependent.
 
That isn't OS dependent, it is filesystem type dependent.
Oh, interesting. Is there any chance you can share any doc explaining why this is happening or provide a brief explanation so I can google further?

Thanks
 
Oh, interesting. Is there any chance you can share any doc explaining why this is happening or provide a brief explanation so I can google further?

Thanks
Many filesystems store directories in data structures more complex than just one name after another. Since there is no useful "on-disk" size to report easily they would just return 0. You don't want a lot of CPU time to determine actual size for a simple stat(2).

Likewise, empty directories don't have to be zero size if they overprovision expecting to be used.
 
Do I understand the problem correctly that FreeBSD ls returns directory contents for "." (dot, as in current directory) and linux ls does not (and not just the "total" being different)?
 
avoid -exec if possible
it will spawn a process for every file/dir it finds
use
find . -type -f -mtime -2 -print0 |xargs -0 ls -ld
 
Back
Top