Most files in the /proc display information about the hardware and currently running processes, and you can change the permission of the files and modify them whenever necessary.
Understanding the /proc Directory
All the files in this directory are stored as virtual files and listed as zero bytes yet contain extensive information. The files get updated constantly, and their time stamps show the current time and date.
The files in the /proc directory get mounted at boot time and can be viewed using commands, such as less and cat.
The common files and their description are listed below:
- /proc/fb: it contains frame buffer devices
- /proc/devices: it contains drivers configured currently for the kernel
- /proc/cmdline: it contains the kernel command line details
- /proc/consoles: all details about current consoles, such as tty
- /proc/cpuinfo: all CPU information gets stored in the file
Viewing the /proc Files
The different files in the /proc directory represent various details. To view all the files contained, you can use the ls command:
In the previous output, you will note there are numbers and files. The numbers represent the PIDs for processes. As for the files, most have the name representing their purpose. For instance, cpuinfo contains the CPU information.
To view the contents of a specific file, list the contents using cat or less commands.
In the following example, we are viewing the memory file using cat.
From the following output, you will note the file contains different information about the system’s memory, including free space.
Also, to get the CPU information, open the cpuinfo file using cat.
Even though most of the contents of the file are viewable using root privileges, some are unreadable and require other commands, such as top, free, or lspci.
For instance, the top command lists all running processes we saw in the /proc directory.
Similarly, to view the PCI devices, you must run the lspci command as its file is not human-readable.
Editing the Files
Most of the /proc files are read-only. The few that are writable, especially those in the /proc/sys, can be changed to adjust different kernel settings.
The syntax to change the values of the writeable files is:
For instance, the hostname gets stored in the /proc/sys/kernel, and you can edit and use a new hostname using the following command. Here, replace the examplehost1 with your preferred hostname:
Running the commands with root privileges edits the kernel details as in the previous example. Besides, you can check the values of given variables using the cat command. For instance, you can run the following command to check if ipv4 packet forwarding is enabled.
The output here is binary with zero representing false, meaning port forwarding is not enabled.
Other Directories in the /proc
For different processes, their directories are numbered in blue, and each name represents the process ID and contains details of the specific process. Inside each process directory, you will get different files, such as maps, fd, exe, and cmdline.
Still, you will note other unnumbered directories, which contain other files. One such directory is the /proc/sys, which contains information about the system and kernel features.
This guide covered the /proc file system in Linux that contains different virtual files. We’ve covered how to list the available files and display the contents of a specific file in the directory.
Furthermore, we have seen how you can change the values for the writable files, provided you have root privileges. Hopefully, you now understand working with the /proc file system in Linux.