Python os.mknod() method
Python OS file/directory methods
Overview
The os.mknod() method creates a file system node with the specified file name (a file, device special file or named pipe).
Syntax
The **mknod()** method syntax is as follows:
os.mknod(filename[, mode=0600[, device=0]])
Parameters
-
filename -- The file system node to create
-
mode -- mode specifies the permissions for creating or using the node, combining (or bitwise OR) stat.S_IFREG, stat.S_IFCHR, stat.S_IFBLK and stat.S_IFIFO (these constants are in the stat module). For stat.S_IFCHR and stat.S_IFBLK, device defines the newly created device special file (possibly using os.makedev()); otherwise it is ignored.
-
device -- Optional, specifies the device for the file being created
Return Value
This method has no return value.
Example
The following example demonstrates the use of the mknod() method:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import stat
filename = '/tmp/tmpfile'
mode = 0600|stat.S_IRUSR
# Specify different modes for filesystem nodes
os.mknod(filename, mode)
The output of the above program is:
-rw-------. 1 root root 0 Apr 30 02:38 tmpfile