1

Lets say that I have a CLI which transforms a file_a into a file_b like so:

transform --input /path/to/file_a --ouptut /path/to/file_b

I have developed a program that use this CLI and need to unit test it when the CLI is executed. But I don't want my tests to deals with disk writing operation.

Does a fake drive exist on Linux where I can write useless files with no persistence?

1 Answers1

2

Even better than /tmp are the tmpfs volumes. These behave like real filesystems but are actually "RAM drives". They offer :

  • read, write and delete is really fast
  • purged at power off and unmount

Distributions (at least Debian does it) usually set up one (or more) for you. List them with :

mount | grep tmpfs

Or :

df -h | grep tmpfs

which also shows the available space. /dev/shm is my favorite candidate.

EDIT :

as said in a comment :

writing to tmpfs files will still fill up your memory and swap.

Which is totally right. The tmpfs volumes, like all other volumes, are not a kind of "magical" area where you can store data without limits. They have a defined size (which is reported by the df ... command above) and filling them up may end up slowing your computer (I say "may" rather than "will" because I've actually never experienced this : never had to write more than a few MB of disposable data).

Httqm
  • 1,136