Wednesday, August 15, 2007

recreate deleted /dev/null

Wikipedia says:
The null device is a special file that discards all data written to it (but reports that the write operation succeeded), and provides no data to any process that reads from it (it returns EOF). In Unix programmer jargon, it may also be called the bit bucket or black hole.

The need to recreate /dev/null does not comes often all the time. But incase the special file was mistakenly deleted, here's a quick way on how to recreate a new /dev/null file.

From Fedora and CentOS box, simply issue as root

# cd /dev

Issuing the below command

# ls -la

should give you the below result if /dev/null does not exist

ls: cannot access null: No such file or directory

Creating it would just be issuing the below as root

# mknod /dev/null c 1 3

After creating the special file owned by root alone, we need to change its mode bits as follows

# chmod 666 /dev/null

Alternatively, this can be done in one shot:

# mknod -m 666 /dev/null c 1 3

Now, try the below command for verification that /dev/null was created successfully

# ls -la /dev/null

crw-rw-rw- 1 root root 2, 2 2007-08-15 08:11 null

It works!


Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy