Troubleshooting unexpected disk thrashing, rogue log generation, or debugging complex background services on Linux requires precise insight into which processes are interacting with storage volumes. While utilities like iotop and lsof provide snapshot summaries of input/output bandwidth or open file descriptors, they cannot stream real-time filesystem operation events across an entire operating system.
fatrace (File Activity Trace) is a specialised Linux command-line tool built upon the kernel’s fanotify API. It captures and reports file events—including file opens, reads, writes, and closes—across all mounted filesystems in real time, displaying the process identifier (PID), the executable binary name, and the exact path of the accessed file.
Understanding fatrace Event Identifiers
When fatrace monitors system activity, it reports operations using concise event flags:
- O (Open): A process opened a file handle.
- R (Read): Data was read from the file.
- W (Write): Data was written or appended to the file.
- C (Close): The process closed the file handle after reading or writing.
Installing fatrace on Linux
fatrace is maintained in the standard software repositories of major Linux distributions:
# Ubuntu and Debian
sudo apt update
sudo apt install fatrace
# Fedora and Red Hat Enterprise Linux
sudo dnf install fatrace
# Arch Linux
sudo pacman -S fatrace
Running Real-Time System Traces
Because fatrace interacts directly with the Linux fanotify kernel interface, it requires root privileges to execute:
sudo fatrace
Terminal will begin streaming every filesystem event occurring across mounted storage volumes:
systemd-journald(482): W /var/log/journal/system.journal
rsyslogd(742): W /var/log/syslog
nginx(1204): O /etc/nginx/nginx.conf
nginx(1204): R /etc/nginx/nginx.conf
nginx(1204): C /etc/nginx/nginx.conf
Press Ctrl + C at any time to terminate the trace session.
Filtering Events by Operation Type
Capturing every read and open operation on a busy server can generate thousands of log lines per second. You can restrict output to specific operations using the --filter (or -f) option:
# Monitor write operations only
sudo fatrace -f W
# Monitor file creation and writing (Open and Write)
sudo fatrace -f OW
Filtering by Specific Process or Command
If you are debugging a specific background daemon or application, use the --command (or -c) flag to isolate its filesystem activity:
# Track only operations performed by python3
sudo fatrace -c python3
# Track only operations performed by dockerd
sudo fatrace -c dockerd
Setting Execution Timeouts and Writing to Log Files
When diagnosing intermittent spikes in disk activity, you can instruct fatrace to run for a designated number of seconds and write the captured trace directly to an output file for offline analysis:
# Run fatrace for 30 seconds and save to a report file
sudo fatrace -s 30 -o /tmp/disk_activity_trace.log
Common fatrace Command Options Reference
| Flag | Option Name | Description |
|---|---|---|
-f |
--filter |
Filters events by type: O (Open), R (Read), W (Write), C (Close). |
-c |
--command |
Restricts output to a specific process or executable name. |
-s |
--seconds |
Specifies a running duration in seconds before automatically stopping. |
-o |
--output |
Writes captured filesystem event logs directly to a designated file. |
-t |
--timestamp |
Prepends human-readable wall-clock timestamps to every recorded event. |
With its minimal footprint and fanotify foundation, fatrace provides developers and system administrators with a fast, targeted method for auditing filesystem interactions on Linux systems.