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: use a capital X in chmod so only directories get execute

Linux and shell
~/tips/tip-linux-chmod-capital-x

chmod -R u=rwX,go=rX /srv/site

Sets sensible permissions in one pass: execute only on directories and already-executable files.

A recursive chmod is where permissions go wrong. Give everything 755 and your text files become executable. Give everything 644 and nobody can enter the directories.

The capital X handles both:

chmod -R u=rwX,go=rX /srv/site

The execute bit is only set on directories, and on files that already have execute for someone. Normal files stay at 644 and directories end at 755, while a script you made executable earlier keeps its bit. One command, no find with two passes.

The caveat is in that last rule. If a plain file happens to have an execute bit for any user, X will give it to the others as well. So if the tree is already messy, clean it first with chmod -R a-x on files, or accept that X follows what is there.

Remember that this changes permissions in place and recursively. Double-check the path before you press enter, especially when it is a variable in a script that might be empty. A recursive chmod on the wrong directory is easy to cause and tedious to repair, so I try it on a copy of the tree first when it matters.

Further reading: chmod man page, On this site: setfacl gives one extra user access without changing the group, On this site: stat -c prints the permissions as numbers

More Linux and shell tips zoxide query -ls project eval "$(fzf --bash)" comm --total a.txt b.txt diff -r -x .git -x '*.log' one two printf '%s\n' a b c d e f | xargs -n1 -P3 --process-slot-var=SLOT sh -c 'echo "slot $SLOT got $0"; sleep 0.2' All Linux and shell tips (178) All topics

Link