LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-09-2010, 03:41 AM   #1
isaaclw
Member
 
Registered: Dec 2009
Posts: 36

Rep: Reputation: 15
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
and it returned only the "pool" directories without even going down.
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?
 
Old 01-09-2010, 05:44 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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"

Last edited by David the H.; 01-09-2010 at 05:46 AM.
 
Old 01-09-2010, 05:58 AM   #3
isaaclw
Member
 
Registered: Dec 2009
Posts: 36

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by David the H. View Post
Code:
find /var/cache/apt-proxy/ -path "*pool" -prune -o "*.bz2"
That throws an error:
Code:
find: paths must preceede expression: *.bz2
Usage: .....
So I tried:
Code:
find /var/cache/apt-proxy/ -path "*pool" -prune -o -name "*.bz2"
But it's listing the "pool" folders.
Its no big deal (I can cut them out if I have to) , but I'm still unsure why it's even including them...

Last edited by isaaclw; 01-09-2010 at 06:41 AM.
 
Old 01-09-2010, 06:04 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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
 
Old 01-09-2010, 07:29 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by David the H. View Post
Perhaps using -wholename instead of -path would help?
You caught the point, David. The following should work:
Code:
find /var/cache/apt-proxy -wholename \*pool -prune -o -name \*.bz2 -print
@isaaclw: you can also take a look at this post, here on LinuxQuestions... a little self-citation!
 
Old 01-09-2010, 08:01 AM   #6
isaaclw
Member
 
Registered: Dec 2009
Posts: 36

Original Poster
Rep: Reputation: 15
ok. this worked exactly how I needed:
Code:
find /var/cache/apt-proxy/ -mindepth 6 -path "*pool" -prune -o -name "*.bz2"
Adding the "mindepth" removed the "pool" folders from the output.

I'll check out the wholename option, but mostly just to learn how find works...
 
  


Reply

Tags
fast, find, prune



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
FIND: Only directories which contain specific files brian.m Linux - General 2 05-07-2009 09:25 PM
Search tools (Affinity, Tracker Search Tool, etc.) not working - don't find any files Adamantus Linux - Newbie 1 03-29-2009 11:21 PM
How can i search word in directories? Whynot Linux - General 1 08-18-2007 04:35 PM
Ignore specific sub directories when using tar MicahCarrick Linux - Software 4 11-16-2006 09:59 AM
Find files, directories that are own by specific user mikeshn Linux - General 2 02-12-2004 03:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration