Closed zdave closed 5 years ago
Awesome, great idea, although the behavior I think is not exactly equivalent. If I understand it correctly, -o
has very low precedence, so:
# Original version:
# Equivalent to: (type is file) and (not in a dot directory)
find -L . -type f -not -path '*/.*/*'
# New version:
# Equivalent to: (type is file) or (name starts with dot; abort)
find -L . -mindepth 1 -type f -o -name '.*' -prune > /tmp/b
In other words, I think the new version might return directory names too (specifically, ones starting with a dot) but it is only supposed to return file names.
Does that analysis sound right to you?
I believe the new version is equivalent; I tested it on a few directories with a bunch of dot files/dirs in and the output was the same. The reason it doesn't print directories is because the -print0
is in the -type f
branch of the or.
Ah got it. That makes sense.
I tested this on a directory with 133,751 eligible files in it:
find -L . -mindepth 1 -type f -print -o -name '.*' -prune | wc -l
find -L . -mindepth 1 -type f -not -path './.*/*' -not -path './*/.*/*' -print | wc -l
Both return the same number of files (and the same files). The -prune
version runs in about 1.5s on average, the other in about 2s on average.
Prune dot dirs, rather than walking through them and ignoring all the files.