[SOLVED] Deleting directories except last two
by chrisguk from LinuxQuestions.org on (#54Z56)
I am trying to delete the directories inside another directory with the following command but for me on Debian 10 its not working:
Code:ls -ltr $APPVER | awk -vvar=echo $APPVER/ '/^d/ {A++;X[++j]=$NF} END{for(i=1;i<=A-5;i++){print "rm -rf " var X[i]}}' | shI get this result:
Code:sh: 1: 34mAPP-2.15/: not foundAPP-2.15 being the directory name.
Can anyone assist?


Code:ls -ltr $APPVER | awk -vvar=echo $APPVER/ '/^d/ {A++;X[++j]=$NF} END{for(i=1;i<=A-5;i++){print "rm -rf " var X[i]}}' | shI get this result:
Code:sh: 1: 34mAPP-2.15/: not foundAPP-2.15 being the directory name.
Can anyone assist?