On 2014-04-27 16:28, Anton Aylward wrote:
On 04/27/2014 09:39 AM, Carlos E. R. wrote:
I'm trying to produce a list of files with 'find' skipping some paths, but I can't find an optimal method. Maybe I just need more coffe.
Perhaps a better description of what "in" and what's "out" would enable some of us who are slightly more conversant with find to help.
I'm simply doing this: find / -type f > listoffiles And I want to avoid these paths to be included in the list: /var/spool/news/ /var/run/udev/links /var/run/user/ /var/run/systemd/ /var/lib/ntp/proc/ /proc/ What I'm doing is generating the full list, then prune it. I was hooping 'find' to have an "--exclude-path", but I can't see such a thing in the large manual.
You might also try reversing things.
The first argument to find is a LIST OF DIRECTORIES.
So you might think about that should be in that list and what should not be in it. In fact you might think about
find $(list generator) -type f
where the embedded script might even be something like
find / -type d -maxdepth 3 -path "xxxx" -regex "yyyy"
for values of xxxx and yyyy that match your needs, possibly negated.
That way you are making find do the work and the outer find only dealing with the directories you want.
This strikes me as being less of a load than having find list every file on the file system and then greping some out.
Mmm.... interesting... [...] Yep... it works, it seems. I have: find "/" -maxdepth 4 -type d > $LISTADO_FIND_DIRS cat $LISTADO_FIND_DIRS | egrep -v "/var/spool/news/" \ | egrep -v "/var/run/udev/links" | egrep -v "/var/run/user/" \ | egrep -v "/var/run/systemd/" | egrep -v "/var/lib/ntp/proc/" \ | egrep -v "/proc/" > $LISTADO_FIND_PRUNED while read FILES ; do find "$FILES" -type f >> $LISTADO_FIND done < $LISTADO_FIND_PRUNED And I get: Telcontar:~ # wc -l encontrarscript* 20659 encontrarscript_listado_dirs 13038 encontrarscript_listado_dirs_pruned 3130530 encontrarscript_listado_ficheros 3164227 total Telcontar:~ # It is still running, the list of files is running and growing. Mmm. I think you propose something instead of my 'while' loop above: find $LISTADO_FIND_PRUNED -type f Where $LISTADO_FIND_PRUNED is a file containing the list of paths to search? -- Cheers / Saludos, Carlos E. R. (from 13.1 x86_64 "Bottle" at Telcontar)