I want to search for a string inside the /sys/class/tty/* directories. So I tried with:

# grep -rn path -e pattern

but it returns nothing. Example:

# cat /sys/class/tty/ttySTM0/iomem_base 

# ls -l /sys/class/tty/ttySTM0/iomem_base 
-r--r----- 1 root root 4096 Jan 17 10:37 /sys/class/tty/ttySTM0/iomem_base

# grep -rn /sys/class/tty/ -e 0x40010000

If I use the same syntax inside another directory it seems to work:

# grep -rn /opt -e Could
# /opt/logs/joku1_log.txt:29:Could not read interface wlan0 flags: No such device

Is there some caveats for such a research? My goal is to find which tty has a specific iomem_base address.

2 Answers 2


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
  • Thanks. I was fooled by the sym links because they are set on directories... instead I checked on files.
    – Mark
    Jul 10, 2020 at 13:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .