Filter strace Output to the Calls You Care About With -e trace=
Cut strace 6.8 output to the system calls that matter using -e trace= with call names, class sets like %file and %network, negation, regexes and status=failed.

A plain strace run of even a tiny program prints dozens of lines before the program's own work starts: the dynamic loader mapping libraries, mmap calls, locale lookups. The calls you want are buried. strace's -e option filters the output to what matters, and its trace= form is the one you will use most. This post covers the filter syntax in strace 6.8 on Linux: single names, the built-in class sets such as %file and %network, negation, regular expressions and the separate status= filter for failed calls. It assumes you have already traced a program once, as in the introduction to strace.
The unfiltered baseline
A tiny command already shows the problem:
strace cat /etc/hostname 2>&1 | wc -l34The exact count varies with the distribution and the glibc version, but a few dozen lines for printing one file is typical. Most of them are startup work you do not need. Filtering reduces it to the calls that answer your question.
Select calls by name
Give -e trace= a comma-separated list of system call names:
strace -e trace=openat,read cat /etc/hostnameopenat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220\243\2\0\0\0\0\0"..., 832) = 832
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/hostname", O_RDONLY) = 3
read(3, "buildhost\n", 131072) = 10
read(3, "", 131072) = 0Only the two named calls appear. The order of calls is preserved, and the arguments are printed in full. The last two lines of the output show cat reading the file and then reading again until it gets zero bytes, which is how end of file is signaled. The older spelling -e openat,read without trace= means the same, because trace is the default qualifier, but the explicit form is clearer.
Names must be the kernel's names. On current systems the open call is openat, not open, because glibc implements open() with the openat system call. Asking for open shows nothing and no error, which is a common source of an empty trace.
Select a class with %
Naming every file-related call is tedious, so strace defines sets prefixed with a percent sign. The ones you will use most:
| Set | What it selects |
|---|---|
%file | calls that take a file name as an argument |
%desc | calls that work on file descriptors |
%network | network-related calls |
%process | process lifecycle: fork, exec, exit, wait |
%memory | memory mapping calls such as mmap and brk |
%signal | signal-related calls |
%ipc | System V IPC calls |
%file is the one to reach for when asking what a program opens:
strace -e trace=%file cat /etc/hostnameexecve("/usr/bin/cat", ["cat", "/etc/hostname"], 0x7ffd9a2b1c78 /* 38 vars */) = 0
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
newfstatat(1, "", {st_mode=S_IFCHR|0620, st_rdev=makedev(0x88, 0), ...}, AT_EMPTY_PATH) = 0
openat(AT_FDCWD, "/etc/hostname", O_RDONLY) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=10, ...}, AT_EMPTY_PATH) = 0
+++ exited with 0 +++Every call that names a path is shown, including execve, access and the status calls. The set definitions are in the strace manual page, which also lists the rest, including %stat, %lstat, %fstat and %memory. Some sets differ slightly between strace versions, so check man strace for the version you run.
Negate with !
Prefix the list with an exclamation mark to show everything except the named calls. In most shells the exclamation mark needs quoting:
strace -e 'trace=!mmap,munmap,mprotect,brk' cat /etc/hostnameThis is useful when a program is dominated by one noisy call. A multi-threaded program spends most of its trace in futex, and -e 'trace=!futex' removes that noise while leaving everything else for context. Negation works with sets too, as in -e 'trace=!%memory'.
Match names with a regular expression
A slash starts a regular expression matched against call names:
strace -e 'trace=/^stat' lsThat selects every call whose name begins with stat, such as statx and statfs, which saves listing each variant. The regular expression form is available in strace 5.x and later; check strace --version if the option is rejected.
Show only failed calls
trace= selects by name. To select by outcome, use the separate status= filter. Failed calls are often the whole story, as when a program cannot find its configuration:
strace -e status=failed cat /etc/hostnameaccess("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
+++ exited with 0 +++Only calls that returned an error are printed. The two failures here are harmless, because cat does not need a preload file or a locale archive, which is a reminder to read the error in context before assuming it is the bug. Combine the two filters to look for failed opens only:
strace -e trace=openat -e status=failed ./myprogramThe values of status= include successful, failed and unfinished. -Z is a short form for -e status=failed.
Add -y and -s to make the filtered output readable
A filtered trace is short, so you can afford more detail per line. -y prints the path next to each file descriptor number, and -s raises the string length limit:
strace -y -s 256 -e trace=read,write cat /etc/hostnameread(3</etc/hostname>, "buildhost\n", 131072) = 10
write(1</dev/pts/0>, "buildhost\n", 10) = 10
read(3</etc/hostname>, "", 131072) = 0The descriptor numbers now carry names, so you do not have to track which number was which file.
A worked example: why does the program not find its config?
Filters are most useful when you start from a symptom. A tool prints cannot read configuration and exits, and nothing says where it looked. Filter to failed file calls:
strace -e 'trace=%file' -e status=failed -s 200 ./mytoolopenat(AT_FDCWD, "/home/dev/.config/mytool/config.toml", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/mytool/config.toml", O_RDONLY) = -1 ENOENT (No such file or directory)
+++ exited with 1 +++The trace answers the question the error message did not: the tool looked in two places, in order, and found nothing in either. The fix is to create the file at one of those paths or to point the tool at another with its option. The whole investigation took one command and two lines of output, which is what a good filter buys you.
The same pattern works for other symptoms. A program that cannot connect: filter on %network and status=failed, and look at the connect line for the address and the error, such as ECONNREFUSED for a closed port or ENETUNREACH for a missing route. A program that dies with a signal: filter on %signal, and the trace ends with the signal name. A program that is slow to start: remove the filter and use -tt to find the gap in the timestamps, then filter on the call before the gap.
Filter after the fact instead
Sometimes you do not know what to filter on until you have seen the whole trace. Capture everything once, then filter the file with ordinary tools:
strace -f -tt -o full.trace ./mytool
grep ENOENT full.trace | headThis keeps the complete record while you look for the pattern. The file can be large for a busy program, so pair it with -s set to a modest value. Once you know which calls matter, rerun with -e trace= to get a clean, small trace you can paste into a bug report.
Pitfalls
A name that does not exist on your architecture is a hard error in recent versions. The error text says the system call name is invalid, which tells you to check spelling and architecture, since 32-bit and 64-bit tables differ.
A filter does not reduce overhead much. strace still stops the program at every system call, so a filter only reduces what is printed. For lower overhead on a busy process, a kernel-side tracer is the better tool.
Output of a traced child can interleave with the program's own output. Redirect strace with
-o fileto keep the two apart.


