-bash: /dev/null: Permission denied

Someone evidently moved a regular file to /dev/null. Rebooting will recreate it, or do

rm -f /dev/null; mknod -m 666 /dev/null c 1 3

As @Flow has noted in a comment, you must be root to do this.


This should fix the issue (as root):

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

What these commands are doing:

  • rmis removing the bogus file that has been created because the expected one was missing;
  • mknod is creating a character device named /dev/null with the appropriate major and minor numbers for a Linux kernel;
  • chmod is setting the permissions for all users to be able to read and write to /dev/null.

The solution suggested by Mark did not work on OpenBSD. However

mknod -m 666 /dev/null -c 2 2

did the trick. I have tested this on OpenBSD 5.6. When the accepted answer is executed /dev/null will block and screw any code reading from it pretty badly.

Tags:

Permissions