brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: find -exec grep -l {} + runs one command for many files instead of one each

Find
~/tips/tip-find-exec-plus-batches

find . -name '*.py' -exec grep -l 'TODO' {} +

Runs a command on batches of matched files instead of once per file.

With -exec … \; find starts the command once per file. That is slow on thousands of files.

find . -name '*.py' -exec grep -l 'TODO' {} +
find . -type f -name '*.sh' -exec chmod +x {} +

A plus sign instead of the semicolon hands the command as many file names as fit on one command line, similar to xargs. {} must come directly before the +. When there are very many files, find starts the command more than once. File names with spaces are safe, since no shell splits them.

Further reading: find manual page

More Find tips find / -maxdepth 1 -fstype proc find /backup -name '*.gz' ! -exec gzip -t {} \; -print 2>/dev/null find /srv/downloads -type f -size +100M -size -1G -exec ls -lh {} + find /srv/data -depth -print find /srv -xdev -samefile /srv/downloads/movie.mkv All Find tips (46) All topics

Link