Mounting in-memory file system as a directory

Requirements

'tmpfs', an in-memory file system can be mounted as a directory. It can be used during compilation of a large program, where multiple read-write operations are performed on the file system. It can be used for security reasons, because all files stay in memory and irrecoverably destroyed after the in-memory file system is unmounted.

Preparation

Creating an empty directory.

mkdir ~/MyDir

Mounting the 'tmpfs' in-memory file system

Simple mounting.

sudo mount -t tmpfs -o size=7G tmpfs ~/MyDir

Extra security options.

sudo mount -t tmpfs -o defaults,nosuid,nodev,size=7G tmpfs ~/MyDir

Checking the correctness of mount operation.

df -hl | grep 'tmpfs'

Unmounting the 'tmpfs' in-memory file system

As soon as in-memory file system is unmounted, all it's contents are irrecoverably destroyed.

sudo umount ~/MyDir