Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Debian GNU/Linux Reference Guide
Prev Home Next

4.5.8 Device files

Device files refer to physical or virtual devices on your system, such as your hard disk, video card, screen, or keyboard. An example of a virtual device is the console, represented by /dev/console.

There are two types of devices:

  • character device

    • This can be accessed one character at a time, that is, the smallest unit of data which can be written to or read from the device is a character (byte).

  • block device

    • This must be accessed in larger units called blocks, which contain a number of characters. Your hard disk is a block device.

You can read and write device files, though the file may well contain binary data which may be an incomprehensible-to-humans gibberish. Writing data directly to these files is sometimes useful for the troubleshooting of hardware connections. For example, you can dump a text file to the printer device /dev/lp0 or send modem commands to the appropriate serial port /dev/ttyS0. But, unless this is done carefully, it may cause a major disaster. So be cautious.


4.5.8.1 /dev/null etc.

/dev/null is a special device file that discards anything you write to it. If you don't want something, throw it in /dev/null. It's essentially a bottomless pit. If you read /dev/null, you'll get an end-of-file (EOF) character immediately.

/dev/zero is similar, only if you read from it you get the \0 character (not the same as the number zero ASCII). See Dummy files, Section 8.6.34.


4.5.8.2 Device node number

The device node number are displayed by executing ls as:

     $ ls -l /dev/hda /dev/ttyS0 /dev/zero
     brw-rw----    1 root     disk       3,   0 Mar 14  2002 /dev/hda
     crw-rw----    1 root     dialout    4,  64 Nov 15 09:51 /dev/ttyS0
     crw-rw-rw-    1 root     root       1,   5 Aug 31 03:03 /dev/zero

Here,

  • /dev/hda has the major device number 3 and the minor device number 0. This is read/write accessible by the user who belongs to disk group,

  • /dev/ttyS0 has the major device number 4 and the minor device number 64. This is read/write accessible by the user who belongs to dialout group, and

  • /dev/zero has the major device number 1 and the minor device number 5. This is read/write accessible by anyone.

In the older system, the installation process creates the device nodes using /sbin/MAKEDEV command. See MAKEDEV(8).

In the newer system, the filesystem under in the /dev is automatically populated by the device filesystem similar to the /proc filesystem.


Debian GNU/Linux Reference Guide
Prev Home Next

 
 
  Published under the terms of the GNU General Public License Design by Interspire