Linux / UNIX: Device files

Q. Can you explain me what is device files and how do I access or see device files? Why UNIX / Linux has device files?

A. Under Linux and UNIX each and every hardware device treated as a file. A device file allows to accesses hardware devices so that end users do not need to get technical details about hardware.

In short, a device file (also called as a special file) is an interface for a device driver that appears in a file system as if it were an ordinary file. This allows software to interact with the device driver using standard input/output system calls, which simplifies many tasks.

Device file two types

There are two types of device files based upon how data written to them and read from them is processed by the operating system and hardware:

  • Character special files or Character devices
  • Block special files or Block devices

Understanding Character special files or Character devices

  • Talks to devices in a character by character (1 byte at a time)
  • Examples: Virtual terminals, terminals and serial modems etc

Understanding Block special files or Block devices

  • Talks to devices 1 block at a time ( 1 block = 512 bytes to 32KB)
  • Examples: Hard disk, DVD/CD ROM, and memory regions etc

Why use device files?

Device file allows transparent communication between user space applications and computer hardware.

Device file location

All device files are stored in /dev directory. Use cd and ls command to browse the directory:
cd /dev/
ls -l

How do I find out the device file type?

Simply use ls -l command:
ls -l /dev
Look for file’s type in the first column output.

A character device is marked with a c as the first letter of the permissions strings.
$ ls -l /dev/console
A block device is marked with a b as the first letter of the permissions strings:
$ ls -l /dev/sdb1

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 18 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
18 comments… add one
  • Rajesh Jan 15, 2009 @ 18:21

    Simple explaination, yet effective. thanks,

  • izee Mar 8, 2009 @ 5:35

    v gud explanation thnx dude……………

  • max Mar 24, 2009 @ 10:09

    cat /proc/devices shows list of character & block files.

  • Rits Aug 15, 2009 @ 10:23

    Yes , very clear explanation indeed… Thanks it answered my query !

  • Anonymous Jun 14, 2010 @ 5:55

    great ..cleared all my doubts

  • Anold Eliapenda Mathayo Jul 5, 2010 @ 5:35

    Thanks to linux for answering my questions. I am a Tanzanian boy studying an Information Technology degree. I am aged 22 years.

  • sree Mar 15, 2012 @ 6:35

    Can u plz tell how to view the contents of those file. When i tried to open a tty file(/dev) it gave for me a message “permission denied”. Can i see the code written inside that file? If so plz let me know how can i view it?

  • ravindranath Apr 3, 2012 @ 5:20

    thanks a lot………

  • hds Jan 6, 2013 @ 17:43

    Thanks for such a good explanation

  • Ajay patwal Aug 24, 2013 @ 6:40

    nice one …………………

  • Tanqulity Sep 29, 2013 @ 8:39

    which type of devices are marked with “d” as the first letter?
    drwxr-xr-x root root 200 sep 29 18:43 snd
    it is a directory right?

  • shweta Feb 1, 2014 @ 9:00

    thank u so much…vry nyc ans

  • aaaa Feb 18, 2014 @ 5:11

    cant get simpler than this!!Thanks you..

  • Kapil Awadhwal May 19, 2014 @ 6:34

    Greate explaination in short… !!!

  • Kapil Awadhwal May 19, 2014 @ 6:35

    Tanqulity: Yes the directories are marked d as the first letter.

  • Sehrish Mukhtar Feb 28, 2015 @ 6:47

    how device driver files are recognized i unix and linex?

  • Sehrish Mukhtar Feb 28, 2015 @ 6:50

    how device drivers files are recognized in unix and linex?

  • Raman Kumar Kharche Nov 2, 2015 @ 5:51

    How the mapping of Virtual Filesystem and the device file takes place.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum