1

I want to grep a particular kernel setting as follows

$ sudo sysctl -a --ignore | grep -i max_map_count 2>/dev/null
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.docker0.stable_secret"
sysctl: reading key "net.ipv6.conf.enp2s0.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
sysctl: reading key "net.ipv6.conf.wlp3s0.stable_secret"
vm.max_map_count = 262144

Since I am both ignoring info about unknown keys (i.e. the --ignore option) and redirecting potential error output to /dev/null, what are these reading jey lines printed?

11

You are redirecting the stderr of the grep to /dev/null but the stderr messages are coming from sysctl. Try

sudo sysctl -a --ignore 2>/dev/null | grep -i max_map_count
5

An explanation of the stable_secrect messages can be found here. In short, the keys exist but are not initialized causing the message.

Concerning your actual command and goal, the pipe | only redirects stdout not stderr which is printed before the rest is sent to the pipe.
To have the expected behaviour you could use one of the commands as follows.

sudo sysctl -a --ignore 2> /dev/null | grep max_map_count
sudo sysctl -a --ignore 2>&1 | grep max_map_count
sudo sysctl -a --ignore |& grep max_map_count

Alternatively you also could use find.

find /proc/sys -name '*max_map_count*' -exec grep -H . "{}" \;

Better would be, as you already know what you are searching for.

sysctl vm.max_map_count

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.