RSS‎ > ‎

Linux :: Why everything on Linux is File

posted Feb 13, 2013, 10:26 PM by Ashish Jain
One of the defining features of Linux is that everything is a file. Things on Linux appear as your file system, but they aren’t actually files. They’re 
special files that represent hardware devices, system information, and other things — including a random number generator. Files can be divided into three categories; ordinary or plain files, directories, and special or device files.

Directories in Linux are properly known as directory files. They are a special type of file that holds a list of the other files they contain.

Ordinary or plain files in Linux are not all text files. They may also contain ASCII text, binary data, and program input or output. Executable binaries (programs) are also files, as are commands. When a user enters a command, the associated file is retrieved and executed. This is an important feature and contributes to the flexibility of Linux.

These special files may be located in pseudo or virtual file systems such as /dev, which contains special files that represent devices, and /proc, which 
contains special files that represent system and process information.

/proc ::  Example, let’s say you want to find information about your CPU. The /proc directory contains a special file – /proc/cpuinfo – that contains this 
information. You don’t need a special command that tells you your CPU info – you can just read the contents of this file using any standard command 
that works with plain-text files. For example, you could use the command cat /proc/cpuinfo to print this file’s contents to the terminal – printing your 
CPU information to the terminal. You could even open /proc/cpuinfo in a text editor to view its contents.
Remember, /proc/cpuinfo isn’t actually a text file containing this information – the Linux kernel and the proc file system are exposing this information 
to us as a file. This allows us to use familiar tools to view and work with the information.

The /proc directory also contains other similar files, for example:
/proc/uptime :: Exposes the uptime of your Linux kernel – in other words, how long your system has been on without shutting down.
/proc/version :: Exposes the version of your Linux kernel.
/dev :: files that represent devices. For example, /dev/cdrom is your CD-ROM drive. /dev/sda represents your first hard drive, while /dev/sda1 represents the first partition on your first hard drive.