Check file created is less than 4 hours or not.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check file created is less than 4 hours or not.
# 8  
Old 06-18-2010
Quote:
Originally Posted by kevintse
Hi Kattoor
This will get you a list of files that were created roughly(not exactly in seconds) 4 hours ago in the current directory.
Code:
ls -l . | awk ' BEGIN { "date +\"%Y-%m-%d\" --date=\"4 hours ago\"" | getline hours } $6 >= hours  { print $8 } '



Hi,

This is listing the time when the files are created in the current directory.

I need to check the files created less than 4 hours from the current time Smilie
# 9  
Old 06-18-2010
I just found out we could use "240 minutes ago", try this for exactly what you want:
Code:
ls -l . | awk ' BEGIN { "date +\"%Y-%m-%d\" --date=\"240 minutes ago\"" | getline minutes } $6 >= minutes { print $8 } '



---------- Post updated at 02:54 AM ---------- Previous update was at 02:45 AM ----------

Quote:
Originally Posted by Kattoor
Hi,

This is listing the time when the files are created in the current directory.

I need to check the files created less than 4 hours from the current time Smilie
ok, now this should work:
Code:
ls -l --time-style=long-iso | awk ' BEGIN { "date +\"%Y-%m-%d\" --date=\"240 minutes ago\"" | getline minutes } $6 >= minutes { print $8 } '

# 10  
Old 06-18-2010
Quote:
Originally Posted by kevintse
I just found out we could use "240 minutes ago", try this for exactly what you want:
Code:
ls -l . | awk ' BEGIN { "date +\"%Y-%m-%d\" --date=\"240 minutes ago\"" | getline minutes } $6 >= minutes { print $8 } '



---------- Post updated at 02:54 AM ---------- Previous update was at 02:45 AM ----------



ok, now this should work:
Code:
ls -l --time-style=long-iso | awk ' BEGIN { "date +\"%Y-%m-%d\" --date=\"240 minutes ago\"" | getline minutes } $6 >= minutes { print $8 } '

Thanks a lot for you reply.

If am using the above command in the delow directory,
total 59472
-rw-r--r-- 1 an_s users 6920 Jan 30 2009 config.xml
-rw-rw-r-- 1 an_s users 13562 May 24 05:06 build.xml
-rw-r--r-- 1 an_s users 7566860 May 24 05:42 CerD.ear
-rw-r--r-- 1 an_s users 1427 May 24 05:42 log4j.xml
-rw-rw-r-- 1 an_s users 7587840 May 24 05:43 Cer.tar
drwxrwxr-x 3 an_s users 4096 May 24 06:27 may24

I am getting the output as,

05:42
05:43
05:06
05:42
06:27
2009

Here it is just printing the exact time not the files created 4 hours back.

Can you please it....
# 11  
Old 06-18-2010
what did you get when you run "ls -l --time-style=long-iso"?
# 12  
Old 06-18-2010
You could use Perl:

Code:
perl -le'(4/24) > -M and print for @ARGV' *

# 13  
Old 06-18-2010
Quote:
Originally Posted by kevintse
what did you get when you run "ls -l --time-style=long-iso"?
am gettin this one if i run ls -l

-rw-r--r-- 1 hiran_s users 7566860 May 24 05:42 CerD.ear
-rw-rw-r-- 1 hiran_s users 7587840 May 24 05:43 CerD.tar
-rw-rw-r-- 1 hiran_s users 13562 May 24 05:06 build.xml
-rw-r--r-- 1 hiran_s users 1427 May 24 05:42 log4j.xml
drwxrwxr-x 3 hiran_s users 4096 May 24 06:27 may24
-rw-r--r-- 1 hiran_s users 6920 Jan 30 2009 config.xml
# 14  
Old 06-18-2010
try adding the "--time-style=long-iso" parameter
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Shell script to check the file sitting in the directory more than 10 hours

Hi, I require shell script to check for any pending files which are sitting in the particular directory for more than 10 hours. Please help me on this...Thank you. (5 Replies)
Discussion started by: kiruthiish
5 Replies

2. Shell Programming and Scripting

Check if file got created in less than 10 hrs

Dear Gurus, I want to check if file got created in less than 10 hrs in .ksh. Here is my requirement In $var5 : I'm storing file name In $var4 I have stored : select to_char(sysdate,'YYYYMMDDHH:MM:SS') from dual; If that file date time is less than 10 hrs, then I need to check if less... (1 Reply)
Discussion started by: thummi9090
1 Replies

3. Shell Programming and Scripting

Check how many minutes ago the last file created

Hi , I need help in getting how many minutes ago the last file, matching some pattern in file name, was created in a folder. Thanks in advance. (8 Replies)
Discussion started by: Anupam_Halder
8 Replies

4. 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

5. Shell Programming and Scripting

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... (6 Replies)
Discussion started by: jimbojames
6 Replies

6. Shell Programming and Scripting

check file exists and created today issue

Morning My other issue I have seems very simple but im just not seeing it. I have a script that checks on a remote share to see if the backups for some systems have run. Its as simple as: find /mnt/ukwcs-net-config/WLAN-Controllers/ -mtime -1 -ls | egrep '(cfg)' > wlanlog.txt cut -c 1-92... (4 Replies)
Discussion started by: ltodd2
4 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

To check the lists of file created between 30-60 min

Hi I have to write a script, that will find out the lists of files in a particular directory, which are created between 30-60 min intervals. (3 Replies)
Discussion started by: velocitnitin
3 Replies

9. 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

10. 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
Login or Register to Ask a Question