What does the script /dev/null do?

14,825

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.

Share:
14,825

Related videos on Youtube

C1sc0
Author by

C1sc0

Updated on September 18, 2022

Comments

  • C1sc0
    C1sc0 over 1 year

    I was sued 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?

    • Lucas
      Lucas almost 11 years
      @thefourtheye ????
  • gosalia
    gosalia almost 11 years
    But when I do script /dev/null it says Script started, file is /dev/null. Why is it so?
  • gosalia
    gosalia almost 11 years
    @Mitch I still don't understand how it answers the question. I think the OP wants to know the effect of executing script /dev/null and not just about /dev/null
  • hanshenrik
    hanshenrik almost 4 years
    script /dev/null prevent any message from appearing on your screen. It supresses the messages, byt directing them to the "black hole." - that's bullshit, script makes A COPY OF ALL YOUR MESSAGES in /dev/null, it doesn't hide/supress anything from you