Reputation: 3499
I have changed this post down to just what I think the main problem is..
There is a need to leave the two latest how to delete all files except the latest three in a folder
ls -t1 /home/jdoe/checks/downloads/*.md5 | head -n +2 | xargs rm -r
This removes the oldest files..
And to test:
ls -t1 /home/jdoe/checks/downloads/*.md5 | head -n +2
We really want to leave the two (2) newest files:
ls -t1 /home/jdoe/checks/downloads/*.md5 | tail -n +2 | xargs rm -r
This does not seem to work..
And to test:
ls -t1 /home/jdoe/checks/downloads/*.md5 | tail -n +2
Thanks!
Upvotes: 0
Views: 58
Reputation: 3499
I was able to get some assistance from one of my co-workers and this appears to be what we need.
ls -1tr /home/jdoe/checks/downloads/*.md5 | head -n -2 | while read f; do
#rm -f "$f"
print "file to delete is $f"
done
Upvotes: 1