How to generate gcode only for first layer?
I understand your question like this:


  I know I could cut the mesh and just slice the bottom of my model, but since I am interested in a given number of layers and the heigh of a layer may change according to settings (e.g.: 0.2mm, 0.1mm, 0.05mm...), I want to find a way to generate an arbitrary number of layers from the full model.  I use slic3r.


If my understanding is correct, then you can achieve what you want with a few steps.

Use verbose GCODE

The setting is under "Print settings → Output Options".  This will output gcode with comments in it.

Save the finishing gcode of a valid printing job

Basically, open a valid gcode file, and save the last few lines (comments will help you to understand which ones, it changes from printer to printer) in a separate file (gcode.tail).  These lines are typically those that move away the nozzle from the print, disable the heating element, the steppers and the part cooling fan.

Prepare the first-lines.sh script

#! /usr/bin/env sh
sed -e '/move to next layer (3)/,$d' $1 &gt; /tmp/gcode.tmp
echo ~/gcode.tail &gt;&gt; /tmp/gcode.tmp
echo /tmp/gcode.tmp


What this script does is:


take a file name from the command line ($1) and savie into gcode.tmp only the part of it up to and excluding the line saying "move to the next layer (3)" (you should actually use the number of layers you actually want here, 3 is just an example).  Again, the presence of such a line depends from you generating "verbose gcode".
append to gcode.tmp the content of the file gcode.tail (here replace ~/ with the actual path on your machine.
output as a stream the full content of gcode.tmp


Set your printer to automatically run the script onto the generated gcode

This setting is again under "Print settings → Output Options". You have to type in the full path to first-lines.sh.  Also remember to make the script executable (chmod +x first-lines.sh).

You can also hover over the textbox to get additional information of how you can access slic3r variables there (for example you may want to read the layer height from the settings and compute within the script the number of layers you want to keep).

Profit

:)

Final notes:


I tried the sed command and have post-processing scripts running on my gcode myself, so it should work, but I haven't tried the full procedure myself, if you encounter bugs please leave a comment so I can fix the answer for everybody. :)
I use slic3r Prusa Edition (I believe these settings are the same, but just in case... you may wish to download that version.
All of the above should work out-of-the-box on all mainstream Linux distributions and OSX.  For windows, it has been suggested in the comments to install CygWin.
Since this procedure still slices the full model and then throw away most of it, you could make it faster by only slicing a reasonably thick "bottom part" of your model.  For example: say that you know you will never want to print more than 5 layers and never with a layer height past 0.3mm... in this case you could only keep the bottom 2mm of your model and you'd be safe for all other combinations of layers and layer heights.  Don't keep exactly 1.5mm though, as this is likely to generate a different top layer than the one in the full model.


Good luck! :)