Create the RAM disk:
diskutil erasevolume HFS+ "ramdisk" `hdiutil attach -nomount ram://1165430` |
(the magic number 1165430 is explained here as the number of 512 byte sectors. The string "ramdisk" is just the name of the disk, which will appear under /Volumes after creation)
Write some stuff to the RAM disk:
echo "hello RAM disk" > /Volumes/ramdisk/hello.txt |
Eject the RAM disk:
diskutil eject /Volumes/ramdisk |
Gathered from here and here so that I remember for later.
On Linux
Found this guide for creating a RAM disk on Linux, but have not tried it yet.