Python os.mknod() Method
os.mknod() Overview
The os.mknod() method is used to create a file system node (file, device special file or named pipe) with the specified file name.
os.mknod() Syntax
The mknod() method syntax format is as follows.
os.mknod(filename[, mode=0600[, device=0]])
os.mknod() Parameters
-
filename – The created file system node
-
mode – mode specifies the permission to create or use nodes, in combination (or bitwise)
-
stat.S_IFREG
-
stat.S_IFCHR
-
stat.S_IFBLK
-
stat.S_IFIFO
S_IFCHR and stat.S_IFBLK, the device defines the latest created device special file (possibly using os.makedev()), everything else is ignored.
-
-
device – Optional, specify the device on which to create the file
os.mknod() Return Value
This method has no return value.
os.mknod() Demo
The following example demonstrates the use of the mknod() method.
#!/usr/bin/python3
import os
import stat
filename = '/root/apidemos_mknod'
mode = 600|stat.S_IRUSR
# File system nodes specify different modes
os.mknod(filename, mode)
Output: