Home > database >  How can I move files from one folder to another created at specific date giving the creation date in
How can I move files from one folder to another created at specific date giving the creation date in

Time:01-03

I am trying to use terminal to move files from one folder to another using creation date.

I am using the script

find /root/call_log/files23 -type f -newermt 2022-06-01 -not -newermt 2022-06-02 -exec mv {} /archive

/root/call_log/files23 is location ... /archive is destination but getting an error missing argument -exec. How can i fix it or is there a better way of doing it

CodePudding user response:

man find gives me following information:

-cnewer reference

Time of the last status change of the current file is more recent than that of the last data modification of the reference file. If reference is a symbolic link and the -H option or the -L option is in effect, then the time of the last data modification of the file it points to is always used.

I propose you use this instead of -newermt.

CodePudding user response:

If you want to move all files in a given folder according to when they were created and not according to the last change, this command will do the work:

find /path/to/source/directory -type f -newermt YYYY-MM-DD -exec mv {} /path/to/target/directory \;

Just replace /path/to/source/directory and /path/to/target/directory with proper absolute locations. YYYY-MM-DD replace with the desired creation date.

  • Related