LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

"find" files of multiple extensions, on one or more directories, excluding multiple subdirectories

Posted 12-07-2019 at 12:43 PM by the dsc
Updated 12-07-2019 at 12:47 PM by the dsc

It took me quite a while to find the correct syntax, only after some dozens of attempts that only worked partly right:

Code:
 find "${PWD}" "/optionally/any/other/path/"  \( -path '*/\.*' -o -name '*notthisfolder*' -o -name '*northis*' -o -wholename "*oteven/thi*" \) -prune -o -iname '*.ext1' -o -iname "*.ext2" -o -iname "*.ext*nsion3"
Where '*/\.*' excludes hidden folders (also files, I guess). All the patterns between the parentheses are supposedly pruned, meaning that "find" doesn't go any deeper once they've found, whereas something like "-not -path" would still go within the undesired path, only skipping the root directory.

"$PWD" is just in case you want a list with the full path rather than with "." starting from where you are.
I've read something along the lines that maybe something like "$(pwd)" or maybe `pwd`, using the command, rather than the variable, might behave better with paths and file names with double spaces and things like that. But I think that the curly brackets and quotes already deals with it, I'm not sure.

I guess it was mainly based on this:

http://www.liamdelahunty.com/tips/li...irectories.php
Posted in Uncategorized
Views 1797 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



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

Main Menu
Advertisement
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