I'm trying to do a recursive search in Terminal to find all files that are not folders; this is to confirm that a large directory structure has no content in it. Is there a way to do this?
Starting with another SuperUser post on finding files with a specific extension and reading the man page for "find", I figured out how to use the Terminal to list all files that not named .DS_store. This is still a long list though. I think it is only directory paths, but it is too many to go through manually. I have been looking for a way to use FIND or grep to exclude folders/paths from the output without luck, but I feel like there must be a way.
So far I've tried this commands. Using prune:
find "$PWD" -name ".ds" -prune -o -name "*.*" | xargs -0 ls -laht -P 1 find "$PWD" -name ".ds" -prune -o | xargs -0 ls -laht -P 1 find "$PWD" -name ".DS_Store" -prune -o | xargs -0 ls -laht -P 1\n find "$PWD" -name ".DS_Store" -prune -o -name "*.*" | xargs -0 ls -laht -P 1\n
Embarrassing to realize the latter gave me my answer.
Using name/iname:
find -name ds find -iname ds find . -iname ds find . -iname "ds" find . -iname ".ds" find . -iname "\.ds" find . -iname "Store" find . -iname ".DS_Store".
All had print.
Finally I got frustrated with find and went to grep:
find . -print | grep -v ds find . -print | grep -v DS
At this point I thought I was set on excluding .DS_Store files. I didn't realize that I would be excluding any files w/ "DS" in the name.
I also have read the man page, and have been googling for things like, [recursive search macos exclude all folders terminal]. That's how I found the post I reference above, as well as https://www.crybit.com/exclude-directories/
but they all end up being about excluding specific directories, not directories as a category.
Not trying to be difficult, I'm just someone who when I start explaining something can be overly thorough and am worried it will take me longer to document them than it took to write the question!
– Jordan Elpern-Waxman Mar 16 '23 at 20:08.DS_Storefiles (incorrectly it turned out), so really I was only asking how to exclude directories. I thought the commands I tried were not related to that, so I omitted them. This put me in a bind though as far as how to show that I had put in effort, and the best I could come up with at the time was the pages I had read. – Jordan Elpern-Waxman Mar 19 '23 at 06:54find "$PWD" -name ".ds" -prune -o -name "*.*" | xargs -0 ls -laht -P 1find "$PWD" -name ".ds" -prune -o | xargs -0 ls -laht -P 1find "$PWD" -name ".DS_Store" -prune -o | xargs -0 ls -laht -P 1\nfind "$PWD" -name ".DS_Store" -prune -o -name "*.*" | xargs -0 ls -laht -P 1\n(embarrassing to realize the latter gave me my answer)Using name/iname:
– Jordan Elpern-Waxman Mar 19 '23 at 07:25find -name dsfind -iname dsfind . -iname dsfind . -iname "ds"find . -iname ".ds"find . -iname "\.ds"find . -iname "Store"find . -iname ".DS_Store"All hadprintfind . -print | grep -v dsfind . -print | grep -v DSat this point I thought I was set on excluding.DS_Storefiles. I didn't realize that I would be excluding any files w/ "DS" in the name. – Jordan Elpern-Waxman Mar 19 '23 at 07:32Generally speaking I do think trying to find information that could contain the answer is an attempt to solve a problem, albeit of a different type than trial and error at the command line. For someone who codes but doesn't know terminal scripting, looking for documentation or examples might be a better start than total stabs in the dark in the terminal.
– Jordan Elpern-Waxman Apr 25 '23 at 14:55