LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 05-14-2021, 07:06 PM   #1
Apprentice+
Member
 
Registered: May 2021
Distribution: Slackware64-Current
Posts: 43

Rep: Reputation: Disabled
Question find, How do I include 2 types of files? Like .txt and .htx ?


Good morning everyone!

Using the find command, How do I include 2 types of files? Like .txt and .htx ?
I am trying to locate the word test inside .txt and .htx files only.
My attempts below did not work!

Thanks

Code:
find -iname "*.txt" "*.htx" -exec grep -l "test" {} \;
find -iname "*.txt *.htx" -exec grep -l "test" {} \;
 
Old 05-14-2021, 07:21 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,326
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
This article should help: https://www.tecmint.com/linux-find-c...es-extensions/
 
1 members found this post helpful.
Old 05-14-2021, 07:33 PM   #3
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,794

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
You need -o (OR)
Code:
find \( -iname "*.txt" -o -iname "*.htx" \) -exec grep -l "test" {} \;
Because the implicit -a (AND) has higher precedence one needs to wrap in parentheses. They must be escaped because they have special meaning in the shell.

The grep can take multiple arguments; then consider {} +
Can be faster than {} \;
 
1 members found this post helpful.
Old 05-14-2021, 07:58 PM   #4
Apprentice+
Member
 
Registered: May 2021
Distribution: Slackware64-Current
Posts: 43

Original Poster
Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by frankbell View Post
Thank you very much, that link helped a lot! I set up my search like this and it worked!
Code:
find . -type f \( -name "*.txt" -o -name "*.htx" \) -exec grep -l "test" {} \;
 
Old 05-14-2021, 08:00 PM   #5
Apprentice+
Member
 
Registered: May 2021
Distribution: Slackware64-Current
Posts: 43

Original Poster
Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by MadeInGermany View Post
You need -o (OR)
Code:
find \( -iname "*.txt" -o -iname "*.htx" \) -exec grep -l "test" {} \;
Because the implicit -a (AND) has higher precedence one needs to wrap in parentheses. They must be escaped because they have special meaning in the shell.

The grep can take multiple arguments; then consider {} +
Can be faster than {} \;
I tested your command and it worked too!
I liked it too, because it had fewer arguments than what I had done above.

Thanks for the explanations!
 
  


Reply



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
[SOLVED] what include am i missing for types like u_int8_t? Martinus2u Slackware 3 03-17-2013 09:17 AM
[SOLVED] awk question - read in txt files, offset data by given amount, output new txt files pomico Programming 19 09-17-2012 11:43 AM
Copy the contents of a txt file to other txt files (with similar names) by cp command Aquarius_Girl Linux - Newbie 7 07-03-2010 12:54 AM
cat onelinefile.txt >> newfile.txt; cat twofile.txt >> newfile.txt keep newline? tmcguinness Programming 4 02-12-2009 06:38 AM
include/linux/types.h and include/linux/posix_types.h kpachopoulos Programming 2 11-26-2005 05:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:42 PM.

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