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: sudo fs_usage shows which files a Mac app is reading and writing

Files
~/tips/tip-macos-fs-usage-file-activity

sudo fs_usage -w -f filesys Mail

Lists the file system calls of one app live, so you see which files it touches.

Every now and then an app writes somewhere I did not expect, or a disk keeps busy for no clear reason. fs_usage shows file system calls live, one line per call.

It needs root, because the man page says it uses the kernel tracing facility. Limit it to one app and to file system events:

sudo fs_usage -w -f filesys Mail

-f filesys keeps only file system events and -w forces the wide format, so the columns do not shrink with the window. The name at the end can be a command name, which matches every process with that name, or a process ID. Other modes for -f are network, pathname, exec, diskio and cachehit.

Without a name it watches all system processes, except itself and a few shells and remote login tools, such as Terminal, sshd and zsh. To stop it after half a minute, add a timeout, and to narrow the output further, pipe it through grep:

sudo fs_usage -w -f filesys -t 30 Mail | grep Library

In the output, each line shows the call, the file descriptor, the byte count and the path. A W after the elapsed time means the process was scheduled out during that call, so the time includes waiting. A failed call shows its errno in brackets, which is a quick way to spot a file the app cannot open.

The caveat is that the paths on screen are your real file names, and the unfiltered stream is long. Read it before you paste any of it into a forum thread or a bug report.

Further reading: fs_usage man page

More Files tips sha256sum -c --ignore-missing SHA256SUMS xxhsum -H64 backup.tar > backup.xxh unzip -j archive.zip -d out/ Files > More > Select > pick files > More > Compress ls -lhS /var/log All Files tips (15) All topics

Link