IF loop to check the time modified


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting IF loop to check the time modified
# 1  
Old 03-15-2013
IF loop to check the time modified

Hi Frnds,

i have a folder test in which files generated daily how to chek the files that are modified on that day as a condition for ex,

Code:
if [ file is modified today ]
then echo "i have got something to do with the file"
else
echo" sorry"
fi

i will have more than 3 to 4 files that are modified today. and if they are modified i have some process to do with that. Please help me

Last edited by mahesh300182; 03-15-2013 at 08:58 PM.. Reason: code tag not used properly
# 2  
Old 03-15-2013
You can use -mtime of find(1). -mtime -1 would list files newer than 24 hours. Alternatively, you can make a timestamp every midnight (from cron), and check with -nt, if your shell's test implementation has it. See man test for details. E.g.:
Code:
find /path/to/dir -mtime -1 > newFiles.lst
...
if grep -q $file newFiles.lst ; then 
  echo "file $file is new"
else
  echo "old stuff"
fi

or
Code:
if [ $file -nt $timestamp ] ; then
  echo "$file is new"
fi

# 3  
Old 03-15-2013
Hi Mirni,

Thanks for th eprompt reply..... i think this will defenitely help me... is -mtime -1 will get the files modified 1 day back right? is there any way to get files modified 30 mins ago...
# 4  
Old 03-15-2013
less than 30 minutes ago: -mmin -30
It's all in the manual: man find
# 5  
Old 03-16-2013
Thanks a lot mirni..... find /mahe -mmin -30 | grep Data gives me name of the files greping Data. but i not ly need the name of file alone , i need the ouput like ls -l (ie) date time ,size,rwx acesss etc... Please help me..
# 6  
Old 03-16-2013
Code:
find /mahe -mmin -30 -ls

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to check when cron was modified

Hi all, We use cron "/usr/rdl/sc/cccron" to execute our jobs. But sometimes it is being changed. but we are not sure when it is changed. how could we find when cron is modified. i checked cron by giving ls -l . but it is showing 2009 year. ls -l /usr/rdl/sc/cccron -r-xr-xr-x 1... (2 Replies)
Discussion started by: Divakar
2 Replies

2. Shell Programming and Scripting

How to check when cron is modified

Hi all, We use cron "/usr/rdl/sc/cccron" to execute our jobs. But sometimes it is being changed. but we are not sure when it is changed. how could we find when cron is modified. i checked cron by giving ls -l . but it is showing 2009 year. ls -l /usr/rdl/sc/cccron -r-xr-xr-x 1... (0 Replies)
Discussion started by: Divakar
0 Replies

3. Homework & Coursework Questions

Grep for modified time

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: is it possible to come up with a list of files that are modified before a certain number of hours only using the... (3 Replies)
Discussion started by: momo.reina
3 Replies

4. Shell Programming and Scripting

Grep for modified time

is it possible to come up with a list of files that are modified before a certain number of hours only using the grep command? ex. list files that were modified less than 10 hours ago i've only managed to list files that were created on the same day, i can't seem to figure out how to work... (3 Replies)
Discussion started by: momo.reina
3 Replies

5. Shell Programming and Scripting

Compare Last Modified Time across Time Zone

Hi, I'm new to shell script programming, I only have Java programming background. I'm writing a shell script to do file synchronization between 2 machines that located at different time zone area. Both machine were set its time zone according to its geographical location (Eg: server is at... (1 Reply)
Discussion started by: python
1 Replies

6. Shell Programming and Scripting

changing modified time

How to change the modified time of a file to any specified time. ls -ltr drwxr-xr-x 2 pipe pipe 4096 Jun 10 10:33 coredump_06062008 ---------------------------------------------------------------------- here file coredump_06062008 last modified time is Jun 10 10:33 and i... (1 Reply)
Discussion started by: ali560045
1 Replies

7. Shell Programming and Scripting

Finding out the last modified time for files

I need to find out the last modified time for the files which are older than 6 months. If I use ls -l, the files which are older than 6 months, I am just getting the day, month and year instead of exact time. I am using Korn shell, and SUN OS. Thanks in Advance, Kiran (3 Replies)
Discussion started by: kumariak
3 Replies

8. Shell Programming and Scripting

getting last accessed and modified time together

actually, i'm making an Intrusion Detection System for education purpose (for project) using Bourne shell. The problem I get in that is:- 1. My application should check if there's some modification or alteration in the directory. 2, For that thing, I need to have every attribute of file and... (1 Reply)
Discussion started by: raku05
1 Replies

9. Shell Programming and Scripting

Check if file modified

Hi, I have a monitoring script that I run, and I would like to automate checking if specific parameter file is modified during the last day or two. How do I do that? (1 Reply)
Discussion started by: nimo
1 Replies

10. UNIX for Advanced & Expert Users

Modified time

How do you change the modified time of a file on UNIX?? (4 Replies)
Discussion started by: frank
4 Replies
Login or Register to Ask a Question