Grep inside /sys file returns nothing

Use either of these instead:

grep -rn /sys/class/tty/* -e 0x40010000 2> /dev/null

grep -Rn /sys/class/tty/ -e 0x40010000 2> /dev/null

The glob in the first command is needed in order to have it follow the symlinks that aren't specified on the command line as the contents of /sys/class/tty are all symlinks to the contents of /sys/devices/virtual/tty and /sys/devices/platform/serial####/tty.

The -R in the second command follows the symlinks by default with no glob being needed.

I added 2> /dev/null to send the Input/output error and Permission denied messages to /dev/null as the output is easier to read when all of that isn't returned.


The entries in /sys/class/tty are symbolic links to directories into a different part of /sys which is organized according to how the devices are connected internally. grep -r doesn't follow symbolic link to directories.

grep -R follows symbolic links, but it's a bad idea to follow directories when traversing /sys recursively because there are infinite loops (/sys/foo/bar is a link to /sys/corge/wibble which links to /sys/foo).

So specify the paths more precisely. This is enough to search in all the files of all tty devices:

grep -l -r -x 0x40010000 /sys/class/tty/*/

By the way, since you already know the whole contents of the file and want the file name, -n is useless and -l gives you uncluttered output. -x helps to avoid false positives (but it isn't necessary here since the content of iomem_base has fixed length).

But since you know the file's base name, just search that one.

grep -l -x 0x40010000 /sys/class/tty/*/iomem_base

Tags:

Grep

Sysfs