[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: find: verzeichnisse auslassen



Hallo,

Am Fri, 25 Mar 2011, Alexander Skwar schrieb:
>2011/3/25 Florian (flobee) <flobee@gmail.com>
>> Ich komme mit "find" gerade nicht weiter.
>> Ich will bestimmte Verzeichnisse nicht weiter durchsuchen um Zeit zu sparen aber das scheint nicht zu funktionieren.
>> eg:
>> #> find /home -type f -and \( ! -path "/home/bigStorage/*" -and ! -path "/home/other/*" \) -newer /tmp/stampfile -print
>[???]
>> Hat jemand Hinweise oder Verbesserungen hierfür?

find /home \
    -path '/home/bigStorage/*' -prune \
    -o -path 'home/other/*' -prune \
    -o -type -f -newer /tmp/stampfile -print

Getestet anhand:

find /usr/src/linux/ \
    -path '*/Documentation/*' -prune \
    -o -path '*/scripts/*' -prune \
    -o -type f -not -name '*.[ch]' -print

Der Vorteil von -prune ist dabei, daß find die Verzeichnisse gar nicht
erst "betritt"/durchsucht (was bei '-not -path foo' der Fall wäre).

Die Logik beim -prune ist leider nicht einfach.

$ strace -efile find /usr/src/linux/ -not -path '*/Documentation/*' \
    -not -path '*/scripts/*' -o -type f -not -name '*.[ch]' -print \
    2>&1 | grep 'Documentation' | wc -l
1313
$ strace -efile find /usr/src/linux/ -path '*/Documentation/*' -prune\
    -o -path '*/scripts/*' -prune -o -type f -not -name '*.[ch]' \
    -print 2>&1 | grep Documentation | wc -l
5

Das sind Zugriffe auf's Documentation-Verzechnis selber.

>Verwende statt der "normalen" / doppelten Anführungszeichen " die
>einzelnen Anführungszeichen ', bzw. gar keine (oder ") und "escape"
>das * durch ein vorangestelltes \; also so:
[..]
>Dadurch wird verhindert, das die *Shell* das "*" auswertet. Wenn
>die Shell das "*" auswerten will, muss sie alle Verzeichnis-/Dateinamen
>ermitteln. Bei ' bzw. \* ist das nicht so.

Quark. Die Bourne/Posix Shells expandiert keine Globs in "", also
auch"*" nicht.

$ ls /var/spool/news/* | wc -l
1075
$ ls "/var/spool/news/*" | wc -l
ls: cannot access /var/spool/news/*: No such file or directory
0
$ $0 --version
GNU bash, version 4.0.35(1)-release (x86_64-suse-linux-gnu)
$ ash -c 'ls "/var/spool/news/*" | wc -l'
ls: cannot access /var/spool/news/*: No such file or directory
0
$ pdksh -c 'ls "/var/spool/news/*" | wc -l'
ls: cannot access /var/spool/news/*: No such file or directory
0
$ zsh -c 'ls "/var/spool/news/*" | wc -l'
ls: cannot access /var/spool/news/*: No such file or directory
0
$ csh -c 'ls "/var/spool/news/*" | wc -l'
ls: cannot access /var/spool/news/*: No such file or directory
0
$ busybox sh -c 'ls "/var/spool/news/*" | wc -l'
ls: cannot access /var/spool/news/*: No such file or directory
0

(/bin/sh ist hier die bash).

Innerhalb von "" werden (IIRC nur) Variablen expandiert,
Process-Substitution (»``«, »$()«), sowie "Arithmetic Expansion"
(»$[]«, »$(( ))«) durchgeführt, aber z.B. wird »(( ))« nicht
ausgeführt, ebenso nicht »<()«. Definitiv nicht durchgefüht werden
"word splitting" (an $IFS) und eben "globbing". Deswegen findest du
gelegentlich auch sowas:

    for foo in "${bar}"/*.jpg; do : ; done

wenn man nicht weiß, ob in $bar Zeichen aus IFS vorkommen können.

HTH,
-dnh

-- 
Some people have no repect of age unless it is bottled.


Reply to: