Search and Compress Files by Modification Date

Introduction

Useful list of example for search and compress files by modification date.

Search by date

Find files updated in the last 24 hours

[root@localhost tmp]# find -type f -mtime 0

Find files updated today

[root@localhost tmp]# find -type f -newermt `date +%F`

Find files updated in the last 48 hours

[root@localhost tmp]# find -type f -mtime -2

Find files modified by yesterday

[root@localhost tmp]# find -type f -newermt `date +%F -d yesterday`

Find files updated in the last 72 hours

[root@localhost tmp]# find -type f -mtime -3

Search for files modified up to 3 days ago

[root@localhost tmp]# find -type f -newermt `date +%F -d -3days`

Find files modified after July 1, 2022

[root@localhost tmp]# find -type f -newermt 2022-07-01

Search by time

Find files updated in the last 3 hours

[root@localhost tmp]# find -type f -mmin -180#OR[root@localhost tmp]# find -type f -newermt `date +%F -d -3hours`

Search by file name

Find TXT files updated today

[root@localhost tmp]# find -type f -newermt `date +%F` -name *.txt

Compress the searched files directly

[root@localhost tmp]# find -mtime -10 | xargs tar cvf archive.tar.gz

 by the author.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Maciej

Maciej

623 Followers

DevOps Consultant. I’m strongly focused on automation, security, and reliability.