Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

Shell Programming and Scripting


Tags
find command, prune

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 1 Week Ago
wolfv wolfv is offline
Registered User
 
Join Date: May 2009
Last Activity: 15 July 2017, 11:01 AM EDT
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

These three finds worked as expected:

Code:
$ find . -iname "*.PDF"
$ find . -iname "*.PDF" \( ! -name "*_nobackup.*" \)
$ find . -path "*_nobackup*" -prune -iname "*.PDF"

They all returned the match:

Code:
./folder/file.pdf

Linux

This find returned no matches:

Code:
$ find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

I was expecting it to match:

Code:
./folder/file.pdf

Linux

I am running Fedora 25.


Moderator's Comments:
find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \) Please use CODE tags correctly as required by forum rules!

Last edited by RudiC; 1 Week Ago at 05:33 AM.. Reason: Changed ICODE tags.
Sponsored Links
    #2  
Old Unix and Linux 1 Week Ago
PikK45 PikK45 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 15 July 2017, 9:15 AM EDT
Location: Chennai
Posts: 581
Thanks: 51
Thanked 75 Times in 73 Posts
What are you trying to filter?
Sponsored Links
    #3  
Old Unix and Linux 1 Week Ago
wolfv wolfv is offline
Registered User
 
Join Date: May 2009
Last Activity: 15 July 2017, 11:01 AM EDT
Posts: 34
Thanks: 5
Thanked 0 Times in 0 Posts
I want a list of all PDF files, excluding file names ending in "_nobackup.pdf" or "_nobackup.PDF", and don't even look in folders ending in "_nobackup".
    #4  
Old Unix and Linux 1 Week Ago
MadeInGermany MadeInGermany is offline Forum Advisor  
Registered User
 
Join Date: May 2012
Last Activity: 25 July 2017, 4:53 PM EDT
Location: Simplicity
Posts: 3,638
Thanks: 285
Thanked 1,217 Times in 1,100 Posts
After -prune there must be -o (or, otherwise) in order to continue with files or non-pruned directories. Then if not a directory and name ends with pdf and name does not have _nobackup then print. The print must be there, otherwise there would be a default print also for the pruned directories.

Code:
find . -type d -name "*_nobackup" -prune -o !  -type d -name "*.[Pp][Dd][Ff]" ! -name "*_nobackup.*" -print

Of course -name "*.[Pp][Dd][Ff]" is identical with -iname "*.PDF", but the latter is not implemented on some Unix find.
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using "mailx" command to read "to" and "cc" email addreses from input file asjaiswal UNIX for Dummies Questions & Answers 2 10-11-2014 09:32 PM
"find . -printf" without prepended "." path? Getting path to current working directory? pstein Shell Programming and Scripting 1 10-02-2011 08:23 AM
awk command to replace ";" with "|" and ""|" at diferent places in line of file shis100 Shell Programming and Scripting 7 03-16-2011 08:59 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 12:52 AM



All times are GMT -4. The time now is 08:46 PM.