linux - Correct way to override file permission /dev/null

07
2014-07
  • DOOM

    I am in a middle of this problem, and not sure which method to follow ?

    I am using a plugin which writes temporary files (*.txt / *.tmp etc.) to /dev/null. The plugin is complicated and changing the path is something i can't.

    I am aware of chown chgrp chmod in this context. Also I think that /dev/null is restructured after every reboot.

    Can anyone please guide me so as to change permission to /dev/null to execute plugin as a nonsudo user ??

  • Answers
  • HopelessN00b

    Changing the permissions on /dev/null won't help. Anything sent there is discarded, so there's nothing to read, regardless of your permissions.

    If you need the data, don't discard it (by sending it to dev/null) in the first place, or copy it before it's discarded.


  • Related Question

    linux - Is there a way to replace /dev/null with an actual file?
  • dbr

    Is there a way to replace /dev/null device with a regular file (or a device that appends to a file, perhaps)? How much data is written to it?

    (This slightly odd question is partially inspired by this..)


  • Related Answers
  • avelldiroll

    I would strongly advise against doing so ... depending on your system the resulting file could grow really fast. However, it's quite easy to have fun with a VM.

    I will describe how to do this during one session, i.e. everything should be back the way they were after a reboot.

    Obviously, this has to be done as root.

    First, you need to delete the current /dev/null:

    rm /dev/null
    

    Then create a replacement file with the same name and some adequate permissions:

    touch /dev/null
    chmod 666 /dev/null
    

    You may now visualize what is sent to /dev/null:

    tail -f /dev/null
    

    Finally to bring back /dev/null to its normal behaviour:

    rm /dev/null
    mknod /dev/null c 1 3
    chmod 666 /dev/null
    
  • Tim Williscroft

    You can delete /dev/null and touch it as root, then restore it's permissions.

    The special device goes away and you get a file instead.

    enjoy.

  • ayrnieu

    On OpenBSD:

    cd /dev
    sudo mv null blah
    sudo touch null
    sudo chmod a+rwx null
    echo foo > /dev/null
    

    Some linuxes AFAIK have special device filesystems - devfs; udev - that may complicate this simple procedure.