How do I edit a file in /proc that can be viewed with cat, but is not editable by mousepad and abiword?

Solution 1:

/proc (manpage, kernel docs) is a virtual filesystem (as is /sys - kernel docs). Files in /proc aren't real files, but ways to access information and settings from the kernel. You shouldn't use an editor to edit files in /proc, but write directly to these files:

sudo sh -c 'echo foo > /proc/some/file'
echo foo | sudo tee /proc/some/file

When you attempt to read or write from it, the kernel converts the actions to system calls internally and does the right thing. Some editors can still view the contents (try Vim, for example), but writing to it is a different story.


For a special class of files, those in /proc/sys (kernel docs, Arch Wiki), there's another alternative. You can use the configuration files in /etc/sysctl.conf and /etc/sysctl.d/*.conf to make permanent changes to their values. A file /proc/sys/foo/bar can be set using a key foo.bar in one of these files.

For example, /proc/sys/vm/swappiness can be set by adding a /etc/sysctl.d/90-swappiness.conf containing:

vm.swappiness = 10

And running:

service procps start

You can also make one-off changes (that won't survive the next reboot) by using the sysctl command directly:

sudo systecl -w vm.swappiness = 10