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 -executable checks whether you can run a file, not only the x bit

Find
~/tips/tip-find-executable

find ~/bin /usr/local/bin -type f -executable

Lists the files the current user can actually execute, instead of guessing from permission bits.

The usual way to find scripts that can run is -perm with some mask. GNU find has a test that asks the real question.

find ~/bin /usr/local/bin -type f -executable

-executable asks the kernel whether the user running find may execute the file, the same check the system uses when you start it. That takes into account who owns the file, which group you are in and things like ACLs, where -perm only reads the bits. The -type f matters, because for folders -executable means you can enter them, and nearly every folder passes.

I find the opposite useful too. Scripts that should run but don’t have the bit set:

find ~/scripts -type f -name '*.sh' ! -executable

There are matching tests called -readable and -writable, and they work the same way.

Keep in mind the answer depends on who runs it. As root, almost everything is readable and writable, and executable as soon as any x bit is set, so the results look different with sudo. Network filesystems and a disk mounted with noexec can also give an answer that doesn’t match what happens when you try to run the file.

Further reading: find(1) 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