## 1\. Why you example did not work as expected
`rm`'s prompts need STDIN to receive your feedback. In your example you used STDIN to pipe a list to the `while` loop though, thus `rm` was getting the answers to it's prompts from your `ls`/`head`/`awk` commands, instead of the user.
The solution is to not use STDIN for providing the list to the loop - e.g.:
for y in $(ls -ltrd * | head -n -3 | awk '{print $NF}'); do
rm -iR $y
done
## 2\. Safer way to do this
Be ready for filenames containing spaces (you don't need `awk`, to get the filename, you can just tell `ls` to only print the filename in the 1st place):
IFS=
for y in $(ls -1qtrd * | head -n -3); do
rm -iR "$y"
done
## 3\. An easier way to do this
As Archemar pointed out: You don't even need a loop (as long as there are no spaces in filenames).
rm -iR $(ls -1qtrd * | head -n -3)