0

I'm using find to find the file cpuinfo_max_freq in the the directory /sys/devices/

This is the command I used, it's not showing me any output:

find /sys/devices/ -name 'cpuinfo_max_freq' 

I also tried adding the -L flag to search inside linked directories too, but it doesn't seem to work, And keeps outputting endlessly and never finishes. But doing a find in the root directory (/) works fine.

Here's the path to the actual file:

/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq 
1
  • "keeps outputting endlessly"? What does it output? Is it permissions denied errors? Do you find the file as expected if you run find /sys/devices/ -name 'cpuinfo_max_freq' 2>/dev/null? What operating system are you using? Commented Oct 19, 2020 at 8:45

2 Answers 2

3

The /sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq path contains symlink components:

$ namei -l /sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq f: /sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq drwxr-xr-x root root / dr-xr-xr-x root root sys drwxr-xr-x root root devices drwxr-xr-x root root system drwxr-xr-x root root cpu drwxr-xr-x root root cpu1 lrwxrwxrwx root root cpufreq -> ../cpufreq/policy1 drwxr-xr-x root root .. drwxr-xr-x root root cpufreq drwxr-xr-x root root policy1 -r--r--r-- root root cpuinfo_max_freq 

The canonical path of the corresponding file is:

$ readlink -f /sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq /sys/devices/system/cpu/cpufreq/policy1/cpuinfo_max_freq 

And that path is among the ones returned by:

 $ find /sys/devices/ -name 'cpuinfo_max_freq' /sys/devices/system/cpu/cpufreq/policy6/cpuinfo_max_freq /sys/devices/system/cpu/cpufreq/policy4/cpuinfo_max_freq /sys/devices/system/cpu/cpufreq/policy2/cpuinfo_max_freq /sys/devices/system/cpu/cpufreq/policy0/cpuinfo_max_freq /sys/devices/system/cpu/cpufreq/policy7/cpuinfo_max_freq /sys/devices/system/cpu/cpufreq/policy5/cpuinfo_max_freq /sys/devices/system/cpu/cpufreq/policy3/cpuinfo_max_freq /sys/devices/system/cpu/cpufreq/policy1/cpuinfo_max_freq 

Unless you pass the -L option or -follow predicate, find doesn't follow symlinks when descending the directory trees rooted at the paths you give it as argument.

find -L would evantually find it (along with /sys/devices/system/node/node0/cpu1/cpufreq/cpuinfo_max_freq, /sys/devices/system/memory/memory8/node0/cpu1/cpufreq/cpuinfo_max_freq, /sys/devices/system/node/node0/subsystem/devices/node0/subsystem/devices/node0/cpu1/cpufreq/cpuinfo_max_freq..., and an infinity of other paths) but find with -L would also get lost in /sys/devices as /sys contains many many symlinks, some of which causing loops.

0

I think you need to specify you're looking for a "regular file" (-type f):

$ find /sys/devices -name 'cpuinfo_max_freq' -type f /sys/devices/system/cpu/cpufreq/policy0/cpuinfo_max_freq 

This works fine on my Debian/RPi OS system

If you're trying it in macOS, forget it... find is a different animal in macOS

1
  • 2
    -type f doesn’t help find find anything; it filters what it does find. Put another way, a given find invocation won’t find anything more if you add more tests to it. Commented Oct 19, 2020 at 12:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.