using find to only search specific directories
I'm trying to figure our how the "-prune" option works. I've searched quite a bit on line, and as far as I can tell, "-prune" works exactly the opposite as it says.
I'm using Apt-proxy, and I want to scan through the folders, and find files that end with "*.bz2" The problem is that the search takes a while because of all the "*.deb" files. Fortunately, they're stored in their own folder: /var/cache/apt-proxy/ubuntu /var/cache/apt-proxy/ubuntu-security /var/cache/apt-proxy/partner each have two folders: "pool", "dist" I want to go into the "dist" folders, and find "*.bz2" files, but not the "pool" folders. so I tried: Code:
find /var/cache/apt-proxy/ -path "*pool" -prune adding the option "-mindepth 6" doesn't do anything... (running mindepth 6 by itself with -name "*.bz2" returns all the files) I was hoping to write this out so that find will return the file as fast as possible, since there really isn't that much to search (assuming the "pool" folder is skipped.) What am I doing wrong? |
As I understand it, -prune basically says to ignore the previous name match, but it doesn't automatically say to print anything else. If you want find to continue to search for other paths, use the -o option to add them to the command afterwards.
I think this should work, but I can't actually test it myself, since I don't have an apt-proxy directory. :) Code:
find /var/cache/apt-proxy/ -path "*pool" -prune -o "*.bz2" |
Quote:
Code:
find: paths must preceede expression: *.bz2 Code:
find /var/cache/apt-proxy/ -path "*pool" -prune -o -name "*.bz2" Its no big deal (I can cut them out if I have to) , but I'm still unsure why it's even including them... |
Whoops, sorry. Forgot to add the -name option there. Truth is, I'm not an expert on find. Perhaps using -wholename instead of -path would help?
You can read more about find, and the prune option, here. http://www.grymoire.com/Unix/Find.html#uh-16 |
Quote:
Code:
find /var/cache/apt-proxy -wholename \*pool -prune -o -name \*.bz2 -print |
ok. this worked exactly how I needed:
Code:
find /var/cache/apt-proxy/ -mindepth 6 -path "*pool" -prune -o -name "*.bz2" I'll check out the wholename option, but mostly just to learn how find works... |
All times are GMT -5. The time now is 05:56 PM. |