Linux command
mknod 命令
安全
权限或系统影响较大,执行前请核对目标。
常用示例
Example
sudo mknod [path/to/device_file] b [major_device_number] [minor_device_number]
Example
sudo mknod [path/to/device_file] c [major_device_number] [minor_device_number]
Example
sudo mknod [path/to/device_file] p
Example
sudo mknod -m [0660] [path/to/device_file] c [major] [minor]
Example
sudo mknod -Z [path/to/device_file] c [major] [minor]
说明
mknod creates block devices, character devices, or FIFOs (named pipes) as special files. Device files provide an interface between user programs and device drivers in the kernel. Block devices transfer data in fixed-size blocks and support buffering (e.g., hard drives). Character devices transfer data character by character without buffering (e.g., terminals, serial ports). FIFOs enable inter-process communication through a named file. Major and minor numbers identify the device driver and specific device instance. These numbers can be specified in decimal, octal (prefix 0), or hexadecimal (prefix 0x).
参数
- -m, --mode=_MODE_
- Set file permission bits to MODE (symbolic or numeric), not the default a=rw minus umask.
- -Z
- Set the SELinux security context to the default type.
- --context=_CTX_
- Like -Z, or if CTX is specified set the SELinux or SMACK security context to CTX.
- --help
- Display help and exit.
- --version
- Output version information and exit.
- b
- Create a block (buffered) special file; MAJOR and MINOR are required.
- c, u
- Create a character (unbuffered) special file; MAJOR and MINOR are required.
- p
- Create a FIFO (named pipe); MAJOR and MINOR must be omitted.
FAQ
What is the mknod command used for?
mknod creates block devices, character devices, or FIFOs (named pipes) as special files. Device files provide an interface between user programs and device drivers in the kernel. Block devices transfer data in fixed-size blocks and support buffering (e.g., hard drives). Character devices transfer data character by character without buffering (e.g., terminals, serial ports). FIFOs enable inter-process communication through a named file. Major and minor numbers identify the device driver and specific device instance. These numbers can be specified in decimal, octal (prefix 0), or hexadecimal (prefix 0x).
How do I run a basic mknod example?
Run `sudo mknod [path/to/device_file] b [major_device_number] [minor_device_number]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -m, --mode=_MODE_ do in mknod?
Set file permission bits to MODE (symbolic or numeric), not the default a=rw minus umask.