I’ve got a git repo, and I have revisions of a file, dated with a unix timestamp. I want to get the oldest file (I.E. the one with the smallest timestamp) and remove it.
Is this possible with Bash alone and if so, how?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to find the oldest file in a directory tree, you can do something like this:
This works as long as the number of files isn’t too large. It’s even easier if you’re willing to delete “all files older than a certain number of days”. For example, if you want to get rid of anything older than 5 days:
You wouldn’t want to run this verbatim; you’d want to provide the appropriate filters to
find— or root it at the approriate directory — so that you’re only deleting files you really want to delete.Obviously you’ll need to commit these deletes to git as well. You could do something like this:
…although note that this could commit changes that you’ve previously staged with “git add”. Some things are best done by hand.