Jump to content
Sign in to follow this  
PiNoY

Restore/Re-Create Deleted /dev/null Linux special file

Recommended Posts

Wikipedia:

 

The Linux null device is a special file that discards all data written to it (but reports that the write operation succeeded). It also 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.

 

So, if your linux /dev/null has been missing or deleted somehow, here's how to re-create the special file. Although, we all know that the need to recreate this special file /dev/null does not comes very often. But in case, here is a way on how to recreate a /dev/null special file.

 

From Fedora and CentOS box, go to /dev folder as root by executing the linux command

 

cd /dev
Followed by linux command to list out files

 

ls -la
Since /dev/null does not exists anymore, the above should give us the below lines

 

ls: cannot access null: No such file or directory

So, to re-create /dev/null special file , proceed to execute the below linux command as root

 

mknod /dev/null c 1 3
Then change its mode bits as follows

 

chmod 666 /dev/null
Alternatively, the below has the same effect with the above

 

mknod -m 666 /dev/null c 1 3

Now, let us try to confirm if we have just re-created /dev/null existence

 

ls -la /dev/null
The above should give us something like

 

crw-rw-rw- 1 root root 1, 3 May 24 19:24 /dev/null
Then that is how to recreate /dev/null special file.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×