2

OSX: would it be possible to create a symbolic link that points to /dev/null e.g. a black hole directory.

I Work at a help desk and we need to sanitize a directory just in case data gets into it at any point. We have some protections that are put in place to mitigate the possibility of data getting into this directory, but due to workflow and things we cannot control, sometimes data ends up in this directory.

I think having this directory being a black-hole would be perfect. eg a symbolic link that points to /dev/null

Not sure if this is possible.

Thanks in advance.

1
  • 1
    You could also set up a folder action in OS X that'd delete everything that is put into the directory. Would that suffice?
    – slhck
    Jun 8, 2013 at 7:01

3 Answers 3

3

This isnt supported out of the box. It is possible to link files to /dev/null but not directories.

e.g.:

ln -s /dev/null ~/.bash_history

You might want to look into FUSE to do this, but you might have better luck just scripting it depending on your needs

1

An alternative to folder actions might be to save a plist like this as for example ~/Library/LaunchAgents/test.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>test</string>
    <key>ProgramArguments</key>
    <array>
        <string>bash</string>
        <string>-c</string>
        <string>rm -rf ~/Documents/Black\ Hole/*</string>
    </array>
    <key>WatchPaths</key>
    <array>
        <string>~/Documents/Black Hole/</string>
    </array>
</dict>
</plist>

It can be loaded with launchctl load ~/Library/LaunchAgents/test.plist or by logging out and back in.

1

You could make a read-only RAM disk:

mydev=$(hdid -nomount ram://1024)
newfs_hfs "$mydev"
mkdir /path/to/readonlydir
mount -t hfs -r "$mydev" /path/to/readonlydir

Note that this is slightly different from what you're asking for -- writing into the mount directory for a readonly disk will give you an error, not just silently vanish the file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .