Search code examples
macosbashfilesearchfile-listing

OSX bash recursively find files sorted by size except in folder


I came across the following command, which nearly does what I need:

find . -type f -print0 | xargs -0 ls -l | sort -k5,5rn > ~/files.txt

Now, I don't have a clue what any of this means (would love an explanation, but not that important).

The one thing I need to add is to not bother with specific folders (i.e. I have a Documents folder with 10s of thousands of Word docs, which is making this command take a long long time).

Can anyone suggest an addition to the above command that will have find ignore a given folder(s)?


Solution

  • Exclude paths matching */Documents/* from find:

    find . -type f ! -path "*/Documents/*" -print 0 | ...