You could use sed to exclude the first five newest files, then delete the rest:
ls -t /u01/1/bin/core.siebprocmw.* | sed '1,5d' | xargs rm -r
Question
I found 5 last core files.
I need to delete all core files except these 5 files.
ls -t /u01/1/bin/core.siebprocmw.* |head -n 5
command to find 5 last files by time.
ls -t /u01/1/bin/core.siebprocmw.* |head -n 5 |xargs rm -r
command remove found last 5 files.
I need to delete all files except these last 5 files. Any ideas?
Solution
You could use sed to exclude the first five newest files, then delete the rest:
ls -t /u01/1/bin/core.siebprocmw.* | sed '1,5d' | xargs rm -r
OTHER TIPS
You could also try
ls -t /u01/1/bin/core.siebprocmw.* | head -n -5 | xargs rm -r
head -n -5 selects everything except the last 5 lines in the output of ls.