Bash: delete based on file date stamp

后端 未结 2 593
难免孤独
难免孤独 2020-12-14 11:51

I have a folder with a bunch of files. I need to delete all the files created before July 1st. How do I do that in a bash script?

2条回答
  •  再見小時候
    2020-12-14 12:29

    This should work:

    find /file/path ! -newermt "Jul 01"
    

    To find the files you want to delete, so the command to delete them would be:

    find /file/path ! -newermt "Jul 01" -type f -print0 | xargs -0 rm
    

提交回复
热议问题