Q. What is a char file and a block file? Is there any difference between them?

These both files are related to writing data and reading data from one place to other place. But the difference between them is how they read/write data.

 

character file: A char file is a hardware file which reads/write data in character by character fashion. Some classic examples are keyboard, mouse, serial printer. If a user use a char file for writing data no other user can use same char file to write data which blocks access to other user. Character files uses synchronise Technic to write data. Of you observe char files are used for communication purpose and they can not be mounted.

Example character files: /dev/autofs, /dev/console, /dev/crash, /dev/lp0, /dev/null, /dev/ppp, /dev/random, /dev/tty etc

ls -l output for a char file:

[root@yumserver dev]# ls -l tty0
crw–w—- 1 root root 4, 0 Dec 31 11:45 tty0
[root@yumserver dev]#

Block file: A block file is a hardware file which read/write data in blocks instead of character by character. This type of files are very much useful when we want to write/read data in bulk fashion. All our disks such are HDD, USB and CDROMs are block devices. This is the reason when we are formatting we consider block size. The write of data is done in asynchronous fashion and it is CPU intensive activity. These devices files are used to store data on real hardware and can be mounted so that we can access the data we written. Have a look at our other post on getting block size of a device.

Block file examples:/dev/loop0, /dev/ram0, /dev/sda1, /dev/sr0.

ls -l output for a block file

[root@yumserver dev]# ls -l sda1
brw-rw—- 1 root disk 8, 1 Dec 31 11:45 sda1
[root@yumserver dev]#

Know more about other file types in Linux and how we can find different files in Linux.

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.