bash - Delete files older than 365 days -


files named name_2016-01-19_00-00-00...

tried script find /path/to/files* -mtime +5 -exec rm {} \; unfortunately files moved linux windows , forth file dates no longer accurate.

the following print files either have no date in name, or date older whatever put in "dummy_2015_01_27" name. once have list of names deleting them trivial.

it assumes there never underscore in name part of filename (i.e. date field 2 when split on _). if that's not true you'll have think of else.

(echo "dummy_2015_01_27"; find /path/to/files -type f) \     | sort --field-separator='_' --key 2 \     | sed '/^dummy_/,$d' 

this works gnu sed (i have v4.2.2), favourite on linux, won't work other sed implementations. likewise, i've tested gnu sort (v8.24).


Comments

Popular posts from this blog

Receive udp packets in android gstreamer -

php - Extract Text from HTTP referer -

matplotlib - PYTHON: Annotate boxes disapear dependant on range -