15

What is the mechanism by which rm /dev/null is prevented? Specifically on FreeBSD, but I'm just as interested in all other Unix based systems.

Jonathan Leffler
  • 5,003
  • 1
  • 30
  • 37
Nektarios
  • 326
  • 3
  • 8

2 Answers2

27

You can actually delete /dev/null as the root user on Linux and BSD systems. Of course, once the system is rebooted /dev/null will be restored. Without rebooting also it is possible to restore /dev/null using the mknod command.

Ethan Bierlein
  • 1,069
  • 2
  • 12
  • 20
anubhava
  • 1,058
  • 9
  • 10
12

Permissions - unless you are running as root (super-user) or possibly one of a select few other users or groups (bin or sys), you do not have write permission in the /dev/ directory, and therefore cannot remove anything from the directory.

If you are root, then you could remove it - but your system would be extremely unhappy. You could recreate it, using the mknod command (or perhaps the mknod() system call). Or you could create a plain file, but that would not have the same special properties as the 'real' /dev/null and would leave your system severely crippled.

It is not a good area for experimentation! (And, if you must experiment, I recommend using a VM rather than your main machine.)

Jonathan Leffler
  • 5,003
  • 1
  • 30
  • 37