Register
It is currently Wed Aug 20, 2014 4:24 pm

question regarding find


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Sun Sep 09, 2012 10:26 pm   

Joined: Sun Sep 09, 2012 10:15 pm
Posts: 2
Hi all,
I wanted to find all the that have both the number 63 and the letter "n". If I execute the following two commands, I get slightly different results.

Code:
find -name "*63*" -name  "*n*"  | wc -l
find: `./.gnupg': Permission denied
find: `./.sane': Permission denied
453

Code:
find -name "*63*" -exec find {} -name "*n*"  \; | wc -l
find: `./.gnupg': Permission denied
find: `./.sane': Permission denied
487

Why am I getting different results?
Why do I get the following message?
Code:
find: `./.gnupg': Permission denied
find: `./.sane': Permission denied

Thanks in advance!!


Top
 Profile  
 PostPosted: Tue Sep 11, 2012 6:12 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
In the first case you're searching for files or directories that have 63 and n in their names.
In the second case you're searching for ones containing n in their names in those which have a 63.

You get these error messages because you don't have the permissions to enter those directories.
Put sudo before your command, or add 2> /dev/null to its end if you want to ignore them.


Top
 Profile  
 PostPosted: Wed Sep 12, 2012 2:06 pm   

Joined: Sun Sep 09, 2012 10:15 pm
Posts: 2
Thanks.
Shouldn't both search return the same?
Quote:
In the first case you're searching for files or directories that have 63 and n in their names.
In the second case you're searching for ones containing n in their names in those which have a 63.

The search in both cases is different, but the final result should be the list of those path that contain 63 and n


Top
 Profile  
 PostPosted: Thu Sep 13, 2012 4:57 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
No?

1) find(1) searches at any level for any name containing 63 AND n.
2) find(1) searches for names containing a n at each level of the directories that have a 63 in theirs.

In the second case you have:
[(number of names matching 63) + (number of names matching n in directories matching 63)] unique result lines.

So, perhaps you got 34 directories which match 63 and contain a filename with a n?

What does the following return?
Code:
find -name '*63*' -exec bash -c 'shopt -s nullglob; for r in "$1"/*; do [[ ${r##*/} = *n* ]] && echo "$r"; done' _ {} \; | wc -l


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP