LinuxQuestions.org
Help answer threads with 0 replies.
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 07-10-2016, 02:35 AM   #1
techie_san778
Member
 
Registered: Jul 2011
Posts: 90

Rep: Reputation: Disabled
What's wrong with this find syntax ?


Hello friends,

I am trying to search for all the .C files under the current directory as well as not to search in the sub-directories. I know -maxdepth is an option but i want to do with prune option. So, here's my command :

$ find . -name '*.c' -a ! -name . -prune
& Here's what i got :
./ORACLE-10G/rlwrap/rlwrap-0.41/src/readline.c
..... (trimming other lines)
./C_Progs/preprocessor/multpln.c
..... (trimming other lines)

Where am i going wrong ? Why find goes down the sub-directories when i have used the prune ? This does not happen when i use the -o operator.
$ find . -name '*.c' -o ! -name . -prune
All the .C files as well as other files are listed. But this time find does not go down the sub-directories. Please suggest.
 
Old 07-10-2016, 04:08 AM   #2
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
IDK... because -o is likely to succeed and -a is likely to fail perhaps? I get subdirectories on both. But you probably don't have directories named xyz.c/ in your tree. Although in my case, searching for .el in an emacs themes tree.
 
Old 07-10-2016, 08:11 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,770

Rep: Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210
The "! -name . -prune" part of the expression is going to be evaluated only if the first term, "-name '*.c'" is true. It is unlikely that you have any directories with names ending in ".c". It's all one logical expression, and "-a" does not mean, "Oh, and BTW also do this."

Last edited by rknichols; 07-10-2016 at 08:13 AM.
 
Old 07-10-2016, 03:31 PM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,768

Rep: Reputation: 1193Reputation: 1193Reputation: 1193Reputation: 1193Reputation: 1193Reputation: 1193Reputation: 1193Reputation: 1193Reputation: 1193
Simply reverse the order. First prune then search for the names to print.
 
1 members found this post helpful.
Old 07-11-2016, 04:22 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
Sounds like you want the -maxdepth option ... http://linux.die.net/man/1/find
 
Old 07-11-2016, 04:34 AM   #6
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by chrism01 View Post
Sounds like you want the -maxdepth option ... http://linux.die.net/man/1/find
Did you read the OP's question?
 
Old 07-12-2016, 02:29 PM   #7
techie_san778
Member
 
Registered: Jul 2011
Posts: 90

Original Poster
Rep: Reputation: Disabled
I figured out the solution is first to use the -prune and then search .C files using -a operator.
 
  


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
Whats wrong with this syntax? AsherSevyn Linux - Newbie 8 12-03-2012 05:47 AM
Ldap syntax wrong ? jonaskellens Linux - Newbie 1 04-29-2011 03:58 AM
Fortran - G95 - Wrong Syntax or wrong compiler settings laucian Programming 1 03-21-2008 10:18 AM
is this redirect syntax wrong? neocontrol Linux - Server 9 03-06-2007 11:19 AM
What's wrong with this iptables syntax?? registering Linux - Security 3 06-16-2004 03:54 PM

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

All times are GMT -5. The time now is 08:10 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