Factor out common code for writing ls shell command. Rework its length