LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 01-10-2011, 09:48 AM   #1
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,485

Rep: Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890
Using find and prune to not print path


So it is always good to be humbled by a simple problem every now and then

I have a directory structure:
Code:
path - dir1 - file1
            - file2
     - dir2 - file1
            - file2
     - dir3 - file1
            - file2
     - dir4 - file1
I wish to display the 'file' under each directory except dir2 so the output looks like:
Code:
path/dir1/file1
path/dir3/file1
path/dir4/file1
I thought -path and -prune were my answer so I have played with what feels likes 100s
of combinations all along the lines of:
Code:
find path -path *dir2 -prune -o -name file1
My issue is I cannot seem to get the output like above as it now displays:
Code:
path/dir1/file1
path/dir2
path/dir3/file1
path/dir4/file1
I would appreciate it if someone could show me the error of my ways
It is after 1am so I am going to claim that as my excuse for not seeing the answer
 
Old 01-10-2011, 09:55 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,488

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Code:
find path -wholename path/dir2 -prune -o -name file1 -print
The important thing to notice is -print. This is because if the expression contains no actions other than -prune, -print is performed on all files for which the expression is true (from man find). It is a rule specific for the -prune action. The expression -path *dir2 or -wholename path/dir2 is true and if you omit any other action in the command line the matched directory name is printed out. Good night!
 
Old 01-10-2011, 10:16 AM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,485

Original Poster
Rep: Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890
Thank .... youuuuuuuu

I knew it was something simple that in my blurry eyed state I just could not see <phew>

And yes... good night
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Using find command with -prune and -xdev learn2bperfect Linux - Newbie 4 02-25-2009 11:22 PM
find using -prune and -size sharky Programming 4 09-24-2008 04:14 AM
Use the prune option in find command frznchckn Linux - General 1 06-06-2007 07:18 PM
How to prune more than one directory using GNU find judgex Programming 1 06-03-2006 11:50 PM
How to prune a print & file server to leave minimal services running wolfpeach Linux - Security 4 06-29-2004 06:35 AM


All times are GMT -5. The time now is 10:06 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration