You wrote: >Subject: how to exclude a directory from find? >Author: debian-user@lists.debian.org at cclink >Date: 11.09.96 21:33 > >I'm trying to search for unused files, but I want to exclude a directory >from the search. I tried >cd /scratch && find . -atime +7 -path ./var -prune -o -print >but it doesn't work. Any clues? > >Carlos If you're only interested in regular files, try adding the `-type f' to the find command, e.g., $ cd /scratch && find . -type f -atime +7 -path ./var -prune -o The -print flag is not really needed as is executed by default. ---- Certainly it would be nice to have something like: $ find . -type !d to match files which are not directories, but I don't know if something like that is possible for find. So if can take your question and rephrase it: Is there any kind of "logical not" affecting a flag in find? Something similar to the `grep -v regexp' as opposed to `grep regexp'. Answers are welcome. When I need something like that, I always end up adding the flag -ls to `find', and piping to `grep -v pattern'. Just to give you an idea of what I have in mind (I haven't tried this... would you?) $find . -ls | grep -v "dr???????? " and if only the filename list is what you need, pipe the ouptut to `cut -c column_number_here- '. As it is written above it will fail, as it filters out a filename with the string `draconiano ', but you got the idea. right? I repeat the above is a dirty/slow/inefficient/ugly/ and _imperfect_ solution :-). I am guessing the ?s attempt to catch any of `the single characters r w x s or - which may appear in the permission string written due to the `-ls' flag to `find'. I am sure there might be better ways of specifying the pattern to match (maybe grep'ing -v all the possibilities : `drwxrwxrwx ', `drwxrwxrw- ', etc). The space at the end is important and the double quoting too to avoid the shell to expand the patttern. Of course, this may not be a solution for including in shell scripts, but if you do it once in a while it might work. Cheers, Lazaro <[EMAIL PROTECTED]>
PS. BTW, the man page for gnu find is the 1st one I recommend to learn thoroughly (I should do it again :-).