I need to delete from a folder all files older than a specific file.Running bash on CentOS 7.I have a solution for this, but I think there should be a more elegant way do it:reference_file=/my/reference/fileget_modify_time(){    stat $1 | grep -Po Modify: \K[0-9- :]*}pit=$(get_modify_time $reference_file)for f in /folder/0000* ; do [[ $pit > $(get_modify_time $f) ]] && rm $f ; done
Delete files older than specific file
bash;shell script;centos
I haven't tried it, but find should be able to handle the whole operation just fine:$ find dir/ -type f ! -newer reference -delete... or...$ find dir/ -type f ! -newer reference ! -name reference -deleteBasically:! -newer reference matches files which have been modified less recently than reference.-delete deletes them.! -name reference excludes reference, in case it is also located under dir/ and you want to keep it.This should delete all files older than reference, and located under dir/.