72

I deleted my /dev/null. How can I restore it?

tshepang
  • 64,472
  • 86
  • 223
  • 290
LanceBaynes
  • 39,295
  • 97
  • 250
  • 349

3 Answers3

100
mknod /dev/null c 1 3
chmod 666 /dev/null

Use these command to create /dev/null or use null(4) manpage for further help.

steve
  • 21,582
  • 5
  • 48
  • 75
harish.venkat
  • 7,313
  • 2
  • 25
  • 30
35

Under many traditional unices, you can recreate devices with their default permissions with the MAKEDEV script. This script is traditionally in /dev but is in /sbin on Ubuntu. Pass it an argument that indicates what devices you want to create; on Ubuntu that's std (you can write MAKEDEV null as well, that creates null as well as a number of other devices).

Under modern Linux systems running udev, you can tell udev to recreate all or some devices based on available drivers and connected hardware, through udevadm trigger:

udevadm trigger --sysname-match=null
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • Is this answer still current? I'm on CentOS 7 and I've just overwritten my /dev/null by mistake, the `udevadm trigger --sysname-match=null` trick didn't work for me, while `mknod -m 0666 /dev/null c 1 3` worked perfectly. – Bozzy Jan 24 '19 at 10:11
  • @Bozzy I know it worked with the pre-systemd udev. I haven't tried recently, but as far as I know this should still work. If you add `--verbose`, does it list `/sys/devices/virtual/mem/null `? – Gilles 'SO- stop being evil' Jan 24 '19 at 22:49
  • Yes, it lists that. I've tried to overwrite again /dev/null on my dev machine, but strangely enough I'm unable to do it here, so I can't do a more in-depth analysis now... – Bozzy Jan 25 '19 at 10:18
0

When I accidentally deleted /dev/null, a simple sudo rebootseemed to restore it. It did cause my desktop icons to go crazy, but no damage seemed to be done If that doesn't the other answers probably will be more help