# [Jelly], 23 bytes

 UZ
 Ç¡=⁶$Þ€Ç$⁴¡ZU$⁵+⁴¤¡Y

[Try it online!]

I'm a bit unsatisfied, but MATL needed some competition. :P

Uses the order `URDL`. Inputs:

 - the input array as an array of padded lines
 - the number of repetitions
 - the move to start from (1 = `U`, 2 = `R`, 3 = `D`, 4 = `L`)

### Explanation


 UZ Helper link. Argument: A (the 2D array)
 U Reverse each line and...
 Z ...transpose. Rotates 90° CCW.

 Ç¡=⁶$Þ€Ç$⁴¡ZU$⁵+⁴¤¡Y Main link. Arguments: A, n (2D array, repetitions)
 Ç Rotate 90° CCW...
 ¡ ...m times. (m = which move to start on)

 Þ Sort...
 € ...each line of the array...
 =⁶ ...based on the characters' equality to " ".
 Ç Rotate 90° CCW.
 $ Combine the sort and rotate to one action.
 ⁴¡ Do that n times. (n = repetition count)

 Z Transpose and...
 U ...reverse each line. Rotates 90° CW.
 $ Combine the transpose and reverse to one action.
 ¡ Do that...
 ⁵+⁴¤ ...m + n times.

 Y Join the array by newlines.

[Jelly]: https://github.com/DennisMitchell/jelly
[Try it online!]: https://tio.run/nexus/jelly#@x8axXW4/dBC20eN21QOz3vUtOZwu8qjxi2HFkaFAumt2iD2kkMLI////x@tnpikkJyikKqgrqOgrpCmkJ6RmQVhg0F2Doidm5evUADkgcULFYoUikvA7FKIojKweLlChYJCJVi8CiKuoB773/S/IQA "Jelly – TIO Nexus"