1

I need to find files matching the following criteria:

  • extension is md
  • within folder . and all subfolders
  • exclude all node_modules folders
  • sort by modified date, latest first across all results

I tried this but I guess my exclude for node_modules is wrong as I still get results including node_modules folders when including the fragment \( ! -iname "node_modules" \):

find $PWD -name "*.md" \( ! -iname "node_modules" \) -print0 | xargs -0 ls -laht

1 Answers1

3

This seems to work but it is very slow when having a lot of subfolders. So I'm open for better solutions:

find "$PWD" -name "*.md" ! -path '*/node_modules/*' -print0 | xargs -0 ls -laht

Update: Based on the hint from Kamil Maciorowski regarding -prune, I came up with this solution which is much faster now:

find "$PWD" -name "node_modules" -prune -o -name "*.md" -print0 | xargs -0 ls -laht -P 1