Move files older than a particular date

On command line, using find, move all jpg files older than two days to a top level directory named older:

  • find . -name "*.jpg" -daystart -mtime +2 -exec mv {} ../older \;

Another eaxample. Move all jpg files created today from dirone to dirtwo:

  • find dirone -name "*.jpg" -daystart -mtime 0 -exec mv {} dirtwo \;

Notes:

-daystart drops the evening files of the day before the day two days ago. I.e. what you get remaining is today’s files and two days before that, starting from midnight of the first day.

 

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s