I'm learning a shell scripting and I'm having problems to structure my script. I need to create a script that exclude files of a specific format (example *.txt), keeping only the 5 most recent files, other format files and folder.
Until now, I've wrote this code below (it doesn't work...):
#!/bin/bash
cd testfolder ; rm $(find -name '*.txt' -exec ls -t | awk 'NR>5')
Thanks in advance for the help!