Find And Delete Oldest File If There Are More Than X Files In A Directory

2 Responses

  1. JP says:

    My files use spaces. How do I make it so “xargs rm -f” doesn’t treat each space as a separate filename?

  2. sk says:

    Hey, sorry for the late reply. If your files contains spaces, use -d option like below.

    ls -1t | tail -n +11 | xargs -d ‘\n’ rm -f

    I have updated the guide now. Thanks for bringing it to my knowledge.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.