Test if a file has a last modified date of within the last 24 hours


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Test if a file has a last modified date of within the last 24 hours
# 1  
Old 03-15-2011
Test if a file has a last modified date of within the last 24 hours

Hi there

Im trying to find a way to test whether the last modified time is older than 1 day or not

so
Code:
#!/bin/bash


if [ $my_static_file has a last modified date of within the last 24 hrs ] ; then
   $TOUCHED = "recently"
else
     $TOUCHED = "not so recently"
fi

ive seen loads of posts where people are using find and the -mtime property but i dont thats applicable in my case, as I have a static file that i want to test every day

is this an easy thing to do?

any help would be great
# 2  
Old 03-15-2011
Like this..?
Code:
if [ $(find /path -mtime -1 -type f -name "my_file.txt" 2>/dev/null) ];then
..
..

# 3  
Old 03-17-2011
thats brilliant thanks

there was another way I found as well
Code:
perl -e 'printf "%d\n" ,(time()-((stat(shift))[9]))/60;' myfile


Last edited by Franklin52; 03-17-2011 at 06:42 AM.. Reason: Please use code tags, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

Arrange file by modified date

Hi, Am performing a find based on filename and result can contain multiple files being found Let's say my find command is find /Archive -f -name 12345.pdf and result of find command is /Archive/Folder A/12345.pdf /Archive/Folder B/12345.pdf please note white space in folder names I... (2 Replies)
Discussion started by: gigagigosu
2 Replies

2. AIX

How do I display a file's last modified date?

I'm using a script that I need to get a file's "last modified date" in a format like 01:51:14 PM. We are running on AIX 6.1.0.0. I can't seem to find the right command parameters. Help! (4 Replies)
Discussion started by: mattadams1983
4 Replies

3. UNIX for Dummies Questions & Answers

Find command to get the modified files past 2 hours

Hello, How to get the modified/created files past 2 hours in Solaris with find command? Thank you. (7 Replies)
Discussion started by: balareddy
7 Replies

4. Shell Programming and Scripting

current date modified file

Hi , In my directory , i have many days file but i want to see all those which are of todays date. i tried this but it gives all the files mtime -0 |ls -ltr I tried the below option as well. 19635 find -iname "*.LOG" -mtime 19636 ls -ltr *.LOG -mtime -1 19637 ls -ltr *.LOG... (7 Replies)
Discussion started by: guddu_12
7 Replies

5. UNIX for Advanced & Expert Users

find files modified by hours instead of minutes

Is there an easy way to find files modified by hours? If you wanted to find something modified by like 28 hours then I know you could do this: find . -mmin -1440It is pain to break out a calculator and calculate in minutes. Could you do something similar to this? I know I don't have the right... (1 Reply)
Discussion started by: cokedude
1 Replies

6. Homework & Coursework Questions

list of files modified 10 hours ago using grep

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: Here is the question: Make a list of files in your home directory that were changed less that 10 hours ago,... (3 Replies)
Discussion started by: fight4love
3 Replies

7. UNIX for Advanced & Expert Users

Finding the modified date time of a file

Hi, I am new bie to Unix. Might be a simple question I am asking. I want to find the last modified time of a file and find the difference between the currrent time and the last modified time. Appreciate, if someone can throw some light on what commands can be used. Cheers, James (2 Replies)
Discussion started by: JamesJoe
2 Replies

8. Shell Programming and Scripting

finding the file which is modified within last 2 hours

hi, I want to find a file which is modified within last 2 hours i am using sun-os i tried find . -name <filename> -mmin 120 i found that mmin option is not supported in sun-os is there any other alternative option suggestions welcome thanks in advance (5 Replies)
Discussion started by: trichyselva
5 Replies

9. Shell Programming and Scripting

modifying date (-10 hours) in the content of a file

Dear Experts, I have a problem. I have a file which has contents such as below, with about 500K lines 34|1|532|2008.10.24 23:41:13|2-1-1-13|90130060128441171|CO0402|0|0x00000201A402000021F6005D4901EC1C2000|0|0|0xE00319FFFFBFFFFE| with field separator "|", the 4th field is the date (date... (3 Replies)
Discussion started by: aismann
3 Replies

10. UNIX for Dummies Questions & Answers

How do I get the last modified date of a file?

I am trying to load a group of files and their last dates modified into a text file that will in turn be used with SQL*Loader to load these files into Oracle. I am using a *.ksh script. I am getting the name of the file in by using the following: for file_ext in 'cat loaddir.ext'; do find... (2 Replies)
Discussion started by: akpopa
2 Replies
Login or Register to Ask a Question