Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I just started using Ubuntu as my main OS and I wanted to learn about things I should not do, and learn by the bad things people have done in the past. I came across these email about horror stories that UNIX & Linux sys admins had done on their own system when they where new. Many of them involved the use of the mknod command to both distory and fix a problem. I've never heard of this command before and the man page within Ubuntu is not very helpful. So my question is, what is this command used for, and what are some examples where it is useful in day to day use?

share|improve this question
This is a good question. +1. –  Faheem Mitha Apr 6 '11 at 8:08
add comment

4 Answers

up vote 21 down vote accepted

mknod was originally used to create the character and block devices that populate /dev/. Nowadays software like udev automatically creates and removes device nodes on the virtual filesystem when the corresponding hardware is detected by the kernel, but originally /dev was just a directory in / that was populated during install.

So yes, in case of a near complete disaster causing the /dev virtual filesystem not to load and/or udev failing spectacularly, using mknod to painstakingly repopulate at least a rudimentary device tree to get something back up can be done... But yeah, that's sysadmin horror story time. Personally, I recommend a rescue USB stick or CD.

Aside from creating named pipes, I can't think of a single possible day-to-day use for it that an end user would need to concern themselves with -- and even that is stretching the definition of 'day to day use'.

share|improve this answer
So it's a VERY specialized way of creating a virtual file that is really used by devices connected to the system as a way of communicating with the system without having to learn how to communicate with the device through it's driver? –  Mark Tomlin Apr 6 '11 at 7:52
But udev is Linux-specific, is it not? Perhaps other Unix-like systems still manually create devices? –  Faheem Mitha Apr 6 '11 at 8:05
@mark Er, no. Creating virtual device files is how software is supposed to communicate with the device through its driver. The driver creates the hook in the kernel; mknod creates the device file that links the hook to a device file that software subsequently can connect to. –  Shadur Apr 6 '11 at 8:23
@Faheem I'm not sure; FreeBSD seems to use devfs and/or devd but I have no personal experience with either. I suspect other unices have worked out their own ways to automate the process of making device nodes though. –  Shadur Apr 6 '11 at 8:25
@mark For example, Alsa generates a series of nodes in /dev/snd corresponding to the various elements of each bit of sound hardware it detected and supports. Software that uses sound can use those devices to generate sound without having to know precisely what kind of sound card they're talking to. –  Shadur Apr 6 '11 at 8:29
show 1 more comment

You can make a named pipe with it.

I use it with one program to read from it, and another one to write into it.

Makes it easier to communicate between processes.

Otherwise, you may create device files, for devices that aren't present.

Also: http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=/com.ibm.aix.cmds/doc/aixcmds3/mknod.htm

share|improve this answer
While you answer was correct, Shadur provided an answer that was clear for all levels of readers so I feel it's the best for people looking for an answer for this question. –  Mark Tomlin Apr 8 '11 at 10:10
I know, I just tried to explain from a practical approach as I do it. Using mknod for something else than making named pipes is more than rare. –  polemon Apr 10 '11 at 5:15
add comment

As oracle DBAs working on raw devices to create Oracle ASM diskgroups, we regularly use mknod to link devices.

The replies above were very helpful to me as we are not system admins. I just wanted to point out that it might be rare from storage admins' point of view to use mknod but from Oracle ASM point of view its a common use. (May be someone could come up with a better way for us?)

share|improve this answer
I'm running ASM on Linux and haven't had any reason to run mknod. I have some udev scripts that make symlinks, but not sure what you need mknod for... Unless you're not on Linux. of course. –  derobert Oct 1 '12 at 15:56
add comment

IMHO, even for making named pipes, the mkfifo command be better than mknod. One, it's self descriptive in it's name, Second, it permits -m option to override umask settings.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.