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.
"find" files of multiple extensions, on one or more directories, excluding multiple subdirectories
It took me quite a while to find the correct syntax, only after some dozens of attempts that only worked partly right:
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
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"
"$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
Total Comments 0