mknod – Create Character and Block Device Files

The mknod command in Linux is used to create character and block device files. A device file is a special type of file that represents a device connected to the computer, such as a hard drive, printer, or keyboard. These files are used by the operating system to communicate with the device. The mknod command allows users to create these files manually.


The syntax for the mknod command is as follows:

  • OPTION: Specifies any additional options for the command.
  • NAME: Specifies the name of the device file to be created.
  • TYPE: Specifies the type of device file to be created. This can be either c for character device files or b for block device files.
  • MAJOR: Specifies the major number for the device file.
  • MINOR: Specifies the minor number for the device file.

The mknod command requires root privileges to run. Here are some examples of how to use the command:

To create a character device file named ttyS0 with major number 4 and minor number 64, run the following command:

sudo mknod /dev/ttyS0 c 4 64

To create a block device file named sda1 with major number 8 and minor number 1, run the following command:

sudo mknod /dev/sda1 b 8 1


Here are the available options for the mknod command:

Option Description
-m MODE Sets the permissions for the device file.
-Z CONTEXT Sets the SELinux security context of the device file.
--help Displays help information for the command.
--version Displays the version of the mknod command.

Troubleshooting Tips

Here are some tips for troubleshooting common issues with the mknod command:

  • Make sure you have root privileges before running the command.
  • Double-check the syntax of the command to make sure you have specified the correct options and arguments.
  • If you receive a “Permission denied” error, try running the command with sudo or as the root user.
  • If you receive a “File exists” error, it means that a device file with the specified name already exists. You can either choose a different name or delete the existing file before running the command again.


  • The mknod command is not commonly used by most Linux users as device files are usually created automatically by the operating system.
  • The major and minor numbers for a device file are used by the operating system to identify the device and determine how to communicate with it. It is important to specify the correct numbers when creating a device file.