0

Can one pls tell a proper to list files within date range on cli. Say between Feb 20 to Mar 2 then mv these files to another dir.

Thanks

don_crissti
  • 82,805
Frank
  • 1
  • 1
  • 1

2 Answers2

1

For find implementations that does not have -newerct (older GNU find and find on BSD systems):

Create two timestamp files and use find to find all files that are newer than the oldest of these and older than the newest:

touch -d 2018-02-20T00:00:00 ts-start
touch -d 2018-03-03T00:00:00 ts-end

find . -type f -newer ts-start ! -newer ts-end ! -name ts-end -exec mv {} /destination ';'

rm -f ts-start ts-end

We have to exclude the ts-end filename as that file fulfills the criteria.

Kusalananda
  • 333,661
0
find -newerct "20 Feb 2018" ! -newerct "2 Mar 2018" -exec mv {} /path/to/target/dir

This uses features introduced in recent versions of GNU find.

There are plenty of other ways to accomplish the same thing with find. See the man page for information about -newerxy, -mtime and other goodies.

user1404316
  • 3,078