Select only the files created in the last 24 hours

Hi There

I am trying to create a shell script (.ksh) that will be run on AIX 5300-10 to scp files from one server to another.

The only files I am interested in are the ones that were created in the last 24 hours of whenever the script was run. There are numerous other files in the source directory that were created some time ago, and I do not want to copy these.

Does anybody have ideas on how this can be achieved? I know there is the find command that I can use, but I do not know if this caters for what I require.

Thank you

find . -mtime 0   # find files modified between now and 1 day ago
                  # (i.e., within the past 24 hours)
find . -mtime -1  # find files modified less than 1 day ago
                  # (i.e., within the past 24 hours, as before)
find . -mtime 1   # find files modified between 24 and 48 hours ago
find . -mtime +1  # find files modified more than 48 hours ago

1 Like

Thanks itkamaraj, that is really helpful!

I note that this command is for files that have been modified, are files that have been created any different?

do man find

you will see all these options

find . -ctime -1 # which are created in less then 1 day from currrent folder.
find . -ctime +2 # finds files which are created older then 2 days from currrent folder

Thank you, that is perfect. I was not aware of the man command.

---------- Post updated at 02:59 PM ---------- Previous update was at 02:03 PM ----------

Sorry to be a pain,

How would I include the find -ctime & SCP commands in a SSH to a remote server?

I have tried the following but it does not seem to be correct:

ssh $source_server "find /interface/outbound/Web -type f -ctime -1 -exec scp /destination directory/{} \;"
for i in `find /interface/outbound/Web -type f -ctime -1`
do
scp $i user@$destination_server:/destination_directory/
done

try this

 
find /interface/outbound/Web -type f -ctime -1 | xargs -ILIST scp LIST user@$destination_server:/destination_directory/