HOWTO Recreate /dev/null

27
May

If something happens that requires you to recreate /dev/null on your *nix system. Don’t fret, it’s easy. The most recent issue I had was that a Capistrano recipe inadvertently clobbered /dev/null. The file looked like this:

1
2
[root@web1 ~]# ls -l /dev/null
-rw-r--r-- 1 capistrano engineering 0 May 26 04:02 /dev/null

Thankfully to bring it back to its original state, just run the following commands:

1
2
3
4
5
6
[root@web1 ~]# rm /dev/null
rm: remove regular empty file `/dev/null'? yes
[root@web1 ~]# mknod /dev/null c 1 3
[root@web1 ~]# chmod 666 /dev/null
[root@web1 ~]# ls -l /dev/null
crw-rw-rw- 1 root root 1, 3 May 26 15:09 /dev/null

Take note of the following things:

  • It is not a joke that the mode of /dev/null needs to be 666. It should be user, group, and world read and write.
  • The user and group ownership here is root.
  • There is no size in the ls like you see in the top one. All you should see are the major (1) and minor (3) device numbers (separated by a comma) prior to the date.

3 Responses to “HOWTO Recreate /dev/null”

  1. […] More: HOWTO Recreate /dev/null […]

  2. Gustavo Vegas says:

    An alternate command for the chmod, if you are weary of typing the 666, is ‘chmod a+rw’ …

Leave a Reply