I have a folder that contains versions of my application, each time I upload a new version a new sub-folder is created for it, the sub-folder name is the current timestamp, here
ls -dt1 /path/to/folder/*/ | sed '11,$p' | rm -r
this assumes those are the only directories and no others are present in the working directory.
ls -dt1
will normally only print the newest directory however the /*/
will
only match directories and print their full paths the 1
ensures one
line per match/listing t
sorts time with newest at the top.
sed
takes the 11th line on down to the bottom and prints only those lines, which are then passed to rm
.
You can use xargs, but for testing you may wish to remove | rm -r
to see if the directories are listed properly first.