Select only the files created in the last 24 hours

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Select only the files created in the last 24 hours
# 1  
Old 06-13-2011
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
# 2  
Old 06-14-2011
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

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 06-14-2011
Thank you

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?
# 4  
Old 06-14-2011
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

# 5  
Old 06-14-2011
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/{} \;"

# 6  
Old 06-14-2011
for i in `find /interface/outbound/Web -type f -ctime -1`
scp $i user@$destination_server:/destination_directory/

# 7  
Old 06-14-2011
try this
find /interface/outbound/Web -type f -ctime -1 | xargs -ILIST scp LIST user@$destination_server:/destination_directory/

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

2. Shell Programming and Scripting

Get filelist in a folder which is created in last x hours

Hi , I am looking for some help in getting the list of files matching some pattern in a folder and those were created in last X hours. Please help. Thanks in advance. (1 Reply)
Discussion started by: Anupam_Halder
1 Replies

3. Shell Programming and Scripting

files older than few hours

Hi All I need to know the command which can be used to list the files which are 3 hours old so that it can be deleted. (3 Replies)
Discussion started by: mskalyani9
3 Replies

4. Shell Programming and Scripting

Check file created is less than 4 hours or not.

Hi, I need to check some files in one directory whether any files has been created before 4 hours(ie, less than 4 hours from the current time). Can anybody help me out..? Thanks in advance..! (21 Replies)
Discussion started by: Kattoor
21 Replies

5. Shell Programming and Scripting

how to list files between last 6 hours to 3 hours

Hi Frens, I want to list some files from a directory, which contains "DONE" in their name, i am receiving files every minute. In this i want to list all the files which are newer than 6 hours but older than 3 hours, of current time i dont want my list to contain the latest files which are ... (4 Replies)
Discussion started by: Prat007
4 Replies

6. Shell Programming and Scripting

How to find files by hours old?

I need to be able to do the following: Find files in multiple directories that are 6 hours older than the current time? I am using KSH I tried mmtime but it was not a valid option Any help would be great. Thank you! (2 Replies)
Discussion started by: llsmr777
2 Replies

7. UNIX for Dummies Questions & Answers

Finding a file created within the last 24 hours

which out of atime, ctime, or mtime are the closest to diplaying only the files created within the last 24 hours. is it even possible to find only the files created in the last 24 hours, because I heard that unix files don't hold the creation time as a property of the file. (3 Replies)
Discussion started by: raidkridley
3 Replies

8. Shell Programming and Scripting

list the file created before 24 hours using ls command

I want to list the files created before past 24 hours using ls command. please help me on this (7 Replies)
Discussion started by: jayaramanit
7 Replies

9. Shell Programming and Scripting

Files created in last 24 hours

I need a script which list the files which is starting with the word heap*** and that is created before past 24 hours.I need the script using find command. please help me on this. (1 Reply)
Discussion started by: jayaramanit
1 Replies

10. UNIX for Dummies Questions & Answers

delete files that are over 2 hours old

guys, I have a need for a script that will delete all files in a given directory that are over 2 hours old. I will set this up to run in cron. I'm having a little trouble coming up with the syntax that will identify these files. Is there a variation of the ls command that I can use to identify... (3 Replies)
Discussion started by: hedrict
3 Replies
Login or Register to Ask a Question

Featured Tech Videos