LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script to Move files (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-move-files-242911/)

jain_rajesh 10-15-2004 05:39 AM

Script to Move files
 
Hi,

I want to write a shell script which will look into the directory for the files which has been modified / updated on today's date and move them into the directory which has been named based on Today's date.

For ex: Suppose that todays date is OCT 15, then it will select all files having date modified/created as OCT 15 and then make a dir OCT 15 and move all these files to this directory.

I am able to get date and make directory accordingly using following cmd

d=`date "+%b %d"
mkdir $d

But I am not able to select files based on date and move them into this folder. Can anyone please tell me how to do that?

Thanks.
Rajesh

homey 10-15-2004 08:53 AM

Here ya go! The modification date is at less than one day ( today )
with the command: -mtime -1

Code:

#!/bin/bash

d=`date "+%b%d"`
mkdir /home/$d

cd /home/stuff
find . -depth -type f -name '*' -mtime -1 -exec mv {} /home/$d \;



All times are GMT -5. The time now is 08:31 PM.