0

In my previous question In find -exec, how to substitue current file by {}?, I have asked about test with find. I want to find all files I do not own. So there is proper find command:

find . -type f ! -user "$USER"

but so should be this one as well:

find . -type f -exec bash -c '
    for pathname do
        [[ ! -O "$pathname" ]] && printf "%s\n" "$pathname"
    done' bash {} +

yet both gives different results .

1) if I do [command one] | wc -c --> 4121

But: [command two] | wc -c --> 236768 (PS: I am searching files in my $HOME).

Both gives different numbers of how many files they found.

2) Both still give in result files, that are directories (yes, directories I do not own and thus - permission denied). They give directories despite having find . -type f type files (not dirs) in argument of option, why? (When I ls -ld one of those directory, none is link or anything else)

Herdsman
  • 340
  • Are you running either of these commands with sudo? You would definitely get "Permission denied" errors when find tries to enter directories not owned by you that you don't have access to. This is most likely why these errors occur. Have you looked at the output (not errors) to try to figure out what the differences in result are? – Kusalananda Apr 13 '20 at 18:41
  • no sudo. That is the point, I am trying to look up only those files I own. I get permission denied after wc (or I only see it after wc, but the error could arise before pipe by find) 2) No I did not look at results, there is many files, that would take a lot of time to compare, neither does diff work, because that would be the other way - big output. Is there any program for that? Anyway, why it is showing directories, when specified type f?
  • – Herdsman Apr 13 '20 at 18:50
  • It is not clear if "showing directories" means that the error messages mention directories, or if the find results mention directories. If you have directories that you don't have access to, I would expect these to show up in error messages. As for comparing, just sort the output and use diff. – Kusalananda Apr 13 '20 at 19:00
  • showing directory was meant by this find: ‘./.cpan/build/Class-Load-0.25-0/t’: Permission denied, this is a directory, that does not belong to me. I would suspect, find was trying to open it in order to recursively find files by my previous command (the original one). So it still search for files, not dirs (and thus does not violate the type f), but I do not know the inner mechanism of find – Herdsman Apr 13 '20 at 19:07
  • 1
    @Herdsman You're right about the origin of that error -- find is trying to explore that directory to find files, and getting that error as a result. As for the differences in files listed: rather than trying to catalog them all, I'd just look at the first few differences, and try to figure out why they're different. – Gordon Davisson Apr 13 '20 at 19:16
  • 1
    Why are you running wc -c? That will count characters, not lines. So it doesn't help you know how many results you got, only how those results were reported. I doubt this is the issue, it just seems strange to use -c here. – terdon Apr 13 '20 at 19:20