0

I am looking for some solution, where I have to move all the directories and files under the source directory to the destination a day before. I want to move the directories till yesterday but not today’s.

find  /temp/source/* -mtime +1 -exec mv -t /temp/destination/ {} \;
berndbausch
  • 1,033
  • 8
  • 12
nasa
  • 1
  • 2
  • Take a look at this question on stack overflow. https://stackoverflow.com/questions/13902104/moving-files-older-than-one-day – suchislife Feb 19 '21 at 02:04
  • This looks something different to my requirement... I wanted to move directories and folders from source to destination. – nasa Feb 19 '21 at 02:23
  • Create a file with a timestamp of midnight, then use `find -newer`. – berndbausch Feb 19 '21 at 04:34
  • Have you looked into using `rsync` with the `--include-from=FILE` option, so that you can first rsync the files listed in a text file you created with `find`, then delete those files after you confirm the destination looks right? – Aaron Feb 19 '21 at 17:20
  • Hi the thing is I want to move the directoriesj and each day the directory gets created with respect to the date. So I wanted to move the directories one day before which are older.. – nasa Feb 19 '21 at 23:34

1 Answers1

0

You need daystart if you want to catch all files up to yesterday 23:59 o'clock:

Measure times (for -amin, -atime, -cmin, -ctime, -mmin, and -mtime) from the beginning of today rather than from 24 hours ago. This option only affects tests which appear later on the command line.

Example:

find /temp/source/* -daystart -mtime +0

Or of you want all files only of today

find /temp/source/* -daystart -mtime 0

Or all files only of yesterday

find /temp/source/* -daystart -mtime 1

You can even define a specific range of days like all files of yesterday and the day before yesterday:

find /temp/source/* -daystart -mtime +0 -mtime -3

PS You should consider -mindepth 1 instead of globbing (*) the subdirectories to find.

mgutt
  • 503
  • 1
  • 7
  • 24