Linux Commands

The /proc File System

The /proc is a special file system on Linux which contains vast information about the system hardware. In some cases, it controls low-level hardware devices.

The /proc file system is a pseudo file system and not a real file system. Except for a few, almost all the files here are read-only.

Beware, the /proc directory holds many files which require deep understanding before you can mess with them. Do not try to alter the files here unless you know what you are doing, or you will end up with an inoperable system. In the worst case, you could lose your Linux system installation.

What Will We Cover?

In this guide, we will see an overview of the /proc file system. We will see some selected subdirectories and files in this folder. Let’s get started.

Use of the /proc File System

Basically, the /proc file system is used for controlling system hardware. It also gives the hardware information of the system, just like lspci, lsusb, lsmod, etc. In fact, it works with more hardware. This directory is an immense source of getting knowledge about our computers.

Use Cases for Different proc Subdirectories and Files

As just described, proc contains large amounts of system information.

Let’s see several examples of /proc files and their subdirectories in action. We can use the cat, more or less commands to view the content of various files:

1. /proc/scsi

The /proc/scsi subfolder keeps data about SCSI devices and has several subfolders and files. The main file of interest here is /proc/scsi/scsi. This file shows all the standard SCSI devices:

$ cat /proc/scsi/scsi

2. /proc/cpuinfo

The /proc/cpuinfo file gives the details of the CPU, like model name, vendor id, CPU cores, and so on:

$ cat /proc/cpuinfo

3. /proc/version

The /proc/version file shows the Linux kernel version and other distribution-specific information:

$ cat /proc/version

Another tool similar to /proc/version file in many aspects is uname. However, the file /proc/version does not show some of the sophisticated hardware details provided by uname.

4. /proc/sys

The /proc/sys subdirectory is another important directory. Besides providing the system information, administrators can use it to act directly on the kernel-level features. Hence, the files within this directory should be used cautiously to avoid kernel instability.

4.1. /proc/sys/kernel

The /proc/sys/kernel is one of the important subfolders. The files contained here directly affect the kernel operations. Let’s see some files here:

domianname: Used for configuration of the domain name of the system

modprobe: Used for setting the location of the program that handles the loading of kernel modules

osrelease: Shows the kernel release number

$ cat /proc/sys/kernel/osrelease

ostype: Shows the OS type for your system

$ cat /proc/sys/kernel/ostype

4.2. /proc/sys/net/

The /proc/sys/net/ is related to networking aspects. For example, it contains directories, such as ethernet/, ipv4/, ipv6/, etc. The files within these directories manage the network configuration of a system.

The directory /proc/sys/net/ipv4 has many important files for managing network settings. Several of these settings work together to block attacks on a system and make the system act as a router.

These files should be handled with the utmost care. Otherwise, the remote connectivity of the system may be affected.

4.3 /proc/sys/vm

The /proc/sys/vm aids in configuring Linux’s virtual memory (VM) subsystems. It contains various files like pagecache, page-cluster, overcomit_memory, etc.

5. /proc/cmdline

The /proc/cmdline file displays the parameters passed to the kernel when it is initialized.

$ cat /proc/cmdline

For example, look at this line from this file:

ro root=/dev/hda2

The “ro” argument shows the kernel is mounted in read-only mode.

6. /proc/devices

The file /proc/devices list different characters and block devices. These devices are those which are configured to be used with the kernel. It excludes those devices whose modules are not loaded into the kernel.

$ cat /proc/devices

7. /proc/filesystem

The /proc/filesystems list all the kernel-supported file systems. The first entry signifies if the file system is mounted or unmounted. The other shows the name of the supported file system.

$ cat /proc/filesystems

8. /proc/meminfo

The /proc/meminfo file reports the RAM usage in the current state. Various commands like the top, ps, and free utilize this file for their output.

$ cat /proc/meminfo

9. /proc/modules

The /proc/modules file shows all the modules loaded into the kernel. The first column is for the module’s name, and the second one represents the memory size of the module. The third column checks whether the module is loaded or not. Then, finally, the last column will check if the module can unload itself automatically.

10. /proc/stat

The /proc/stat file keeps logs of different system statistics since last we restarted it. The entries of this file can be very lengthy, something like this:

$ cat  /proc/stat

cpu  100007 739 321605 2239006 1504 0 8007 0 0 0

cpu0 213 0 287664 52897 3 0 0 0 0 0

cpu1 16327 228 4936 228482 208 0 7447 0 0 0

cpu2 13590 89 4493 327198 141 0 42 0 0 0

cpu3 13378 25 4398 327162 440 0 65 0 0 0

cpu4 17739 39 4340 323080 169 0 6 0 0 0

There are several important statistics, such as:

10.1. cpu

It calculates the number of the jiffies for which the system is in user mode, user mode with low priority, system mode, etc. The gross of all the CPUs is measured and is then listed CPU-wise.

10.2. page

It is the number of memory pages written in and out to disk by the system.

10.3. swap

It is the number of swap pages brought in and out to disk by the system.

Conclusion

In this article, we have given a high-level view of the /proc file system in Linux. As you have already seen in this article, /proc file system contains a vast collection of system information; as such, it’s impossible to cover it entirely in this blog. However, you can also refer to man pages to get insight into various other /proc utilities.

About the author

Ali Imran Nagori

Ali imran is a technical writer and Linux enthusiast who loves to write about Linux system administration and related technologies. You can connect with him on LinkedIn
.