What does the script /dev/null do?
I was su
ed into another user to run screen, but I got the error Cannot open your terminal '/dev/pts/4' - please check.
I found a solution: script /dev/null
and after that I can use screen. Why does this work? It creates a new pseudo terminal?
Solution 1:
On UNIX, this is a virtual-file that can be written to. Data written to this file gets discarded. It is similar to the file call NUL on Windows machines.
Key point; When rooting a machine, intruders will often redirect logging to /dev/null
For example, the command ln -s /dev/null
.bash_history
will cause the system to stop logging bash commands.
In layman's terms, it means much the same thing as black hole. Typical usage: if you don't like what I have to say, please direct your comments to /dev/null
.
Think of /dev/null as a "black hole." It is the nearest equivalent to a write-only file. Everything written to it disappears forever. Attempts to read or output from it result in nothing. Nevertheless, /dev/null can be quite useful from both the command line and in scripts.
- It discards all data written to it but reports that the write operation succeeded.
- It means redirecting both standard output and error to
/dev/null
- It prevents the script from displaying anything. like windows "echo off"
script /dev/null
prevent any message from appearing on your screen. It supresses the messages, byt directing them to the "black hole."
Also, have a look at Why does redirecting 'script' to /dev/null/ allow 'screen' to work while su'ed as another user?
Source:Linux Dictionary
Solution 2:
Basically script saves all terminal dialogue into a file, when you specify /dev/null as the file all the stuff script would save into a file would be saved into the black hole.