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: grep -L lists the files that do not contain a pattern

Linux
~/tips/tip-linux-grep-l-files-without-match

grep -L 'Restart=' /etc/systemd/system/*.service

Find the config files where a setting is missing, not the ones where it is set.

Searching for text is easy. Searching for files where something is missing is the more useful question when you check a set of config files.

grep -L 'Restart=' /etc/systemd/system/*.service

The capital -L prints the name of every file that has no match, and nothing else. Here that means every unit file without a Restart= line, so the services that stay down when they crash. Its partner, lowercase -l, lists the files that do match.

Add -r to walk a whole folder:

grep -rL 'X-Frame-Options' /etc/nginx/sites-enabled/

That gives you every site config that does not set that header. I like this for quick audits: a short list of files to look at, instead of scrolling through a list of matches and noticing what is absent.

Combine it with -i when the case of a setting can vary, and with -F when the text contains dots or brackets.

One thing to keep in mind is that a setting can live somewhere else. A unit file may get Restart= from a drop-in in a .d folder, and an nginx site can inherit a header from an included snippet. A file on the -L list is a reason to look closer, not proof that the setting is missing in the running config.

Further reading: GNU grep manual: general output control

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link