Find files modified in previous minute only


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Find files modified in previous minute only
# 1  
Old 12-03-2014
Display Find files modified in previous minute only

Hi,

How can I get files which are modified only in last minute ? it should not display 2 minutes back file
Code:
ls -la 

-rw-rw-r-- 1 stuser st  51 Dec  3 09:22 a.csv
-rw-rw-r-- 1 stiser st  50 Dec  3 09:25 b.csv
-rw-rw-r-- 1 stuser st  53 Dec  3 09:33 c.csv

When I run command at 9:34am then I should see only 9:33am file and not remaining 2 files because those were modified before 9:33am

Thanks

Last edited by rbatte1; 12-03-2014 at 01:45 PM.. Reason: Added CODE tags and set upper case for beginning of sentence and for first person singular
# 2  
Old 12-03-2014
One way would be to create a reference file with a timestamp to look back to. If you run it at 09:34 on 3rd December 2014, and you need to find files newer that 09:33:00 then you can (working out the values of course):-
Code:
touch -mt 201412030934 /tmp/ref_file
find . -newer /tmp/ref_file

The format value is in the manual page for the touch command.

If you need to include the seconds to get a more accurate 'previous minute' then simply add the seconds part, e.g.:-
Code:
touch -mt 201412030934.22 /tmp/ref_file
find . -newer /tmp/ref_file

If you have support for the -d flag, then you could do this:-
Code:
touch -md "1 minute ago" /tmp/ref_file
find . -newer /tmp/ref_file


I hope that this helps,
Robin
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 12-03-2014
If you want the clock minute only, use two marker files, one touched to prior minute:00 and the second to current minute:00, and "find . . . -newer f1 ! -newer f2", possibly with an escape on the ! = \!. Thus, you get a 60 second snapshot of one specific clock minute. This is more useful statistically, else the set may reflect 61 to 119 seconds.
This User Gave Thanks to DGPickett For This Post:
# 4  
Old 12-03-2014
Display

hi batte,
thanks for the solution. it worked. but i have 2 questions in that

1) how can i get files display with date and bytes information just like how it displays when we issue ls -la ?

2) what if i want to give minutes range to get files ?

ex: Want to display all the files between 201412030930 to 201412031230 ?

Sorry that i extended the question scope

Appreciate
# 5  
Old 12-04-2014
You have a way to get the list of files, so you have several options depending on what find supports:-
  • Add a section -exec ls -l {} \+
  • Add a section -exec ls -l {} \; which is slower than the above but sure to be available
  • Add another command the end find ...... | xargs ls -l
To get files by a range of minutes, DGPickett has already given you the tools to do this, but you were probably typing your reply when that was submitted.

There are probably plenty of other ways too. Do any of these appeal?


Robin
# 6  
Old 12-04-2014
Thanks

between dates working in this way

Code:
touch -t 201412031400 first && touch -t 201412031459 last && find / -newer first ! -newer last

appreciate for your answers


Moderator's Comments:
Mod Comment
Please use CODE tags for code, files, input and output/errors
It makes it much easier to read and multiple spaces are respected which can be important for formatting or fixed-width input

Last edited by rbatte1; 12-04-2014 at 10:57 AM.. Reason: Added CODE tags
# 7  
Old 12-04-2014
Quote:
Originally Posted by sbjv
Thanks

between dates working in this way

Code:
touch -t 201412031400 first && touch -t 201412031459 last && find / -newer first ! -newer last

appreciate for your answers


Moderator's Comments:
Mod Comment
Please use CODE tags for code, files, input and output/errors
It makes it much easier to read and multiple spaces are respected which can be important for formatting or fixed-width input
And to get the output in the same format as the output from ls -la, try:
Code:
touch -t 201412031400 first && touch -t 201412031459 last && find / -newer first ! -newer last -exec ls -ld '{}' +

or, if you only want regular files to be included in the output:
Code:
touch -t 201412031400 first && touch -t 201412031459 last && find / -type f -newer first ! -newer last -exec ls -l '{}' +

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep from file modified one minute ago

Hello, I have a list of files, an example below: -rw-r--r-- 1 smf_oper esg 910773 Jul 6 12:52 am1slc02_ACS_201607061242571_20346.cdr -rw-r--r-- 1 smf_oper esg 995838 Jul 6 12:52 am1slc01_ACS_201607061243125_19895.cdr -rw-r--r-- 1 smf_oper esg 557235 Jul 6 12:52... (5 Replies)
Discussion started by: nms
5 Replies

2. Shell Programming and Scripting

Find list of files modified for a given day ?

find list of files modified for a given day ? if i have 10 files in my directory, i have modified only 5 ... how to display only modified files ? (1 Reply)
Discussion started by: only4satish
1 Replies

3. Shell Programming and Scripting

Find files modified in last hour sunOS 5.10

trying to find a way to locate files modified in the last hour in a shell script, unfortunately the command 'find . -mmin -60' is not supported on SunOS 5.10 (works on OpenSolaris 5.11 :mad:) Does anyone know a method of doing this in shell script on 5.10? cheers (19 Replies)
Discussion started by: rich@ardz
19 Replies

4. UNIX for Dummies Questions & Answers

Find last modified date for many files

Hello all - I've looked and have not been able to find a "find" command that will list the last modified date of files within a specific directory and its subdirectories. If anyone knows of such a command it would be very much appreciated! If possible, I would like to sort this output and have... (5 Replies)
Discussion started by: MichaelH3947
5 Replies

5. UNIX for Dummies Questions & Answers

how to find the modified files before 60 mins?

hi, I need to find all the modified files before 60 minutes in a folder. Is that possible to find using mtime in minutes? Suggestions please. Thanks for looking into it... Geetha (8 Replies)
Discussion started by: iamgeethuj
8 Replies

6. Shell Programming and Scripting

help: find and modified files script

hello all im a newbie in the linux world ..i have just started creating basic scripts in linux ..i am using rhel 5 ..the thing is i wanted to create a find script where i could find the last modified file and directory in the directory given as input by the user and storing the output in a file so... (6 Replies)
Discussion started by: tarunicon
6 Replies

7. Shell Programming and Scripting

find files modified more than a day

Hi All, I am using the below command to check the files modified within last 24hours find /home/karthik -mtime -1 -type f -exec ls -l {} \; What parameter do i need to add in the above command to check the files modified in last 2 or 3 days Kindly let me know if any other alternative... (2 Replies)
Discussion started by: karthikn7974
2 Replies

8. UNIX for Advanced & Expert Users

find files modified in a specific month

hello i need a way to list files modified in a specific month and move them to a specific directry , i mean somthing like : find . -modifiedtime "May" -print -exec /usr/bin/mv newdirectory thank u (1 Reply)
Discussion started by: omer_ome
1 Replies

9. Solaris

find files modified in a specific month

hello i need a way to list files modified in a specific month and move them to a specific directry , i mean somthing like : find . -modifiedtime "May" -print -exec /usr/bin/mv newdirectory thank u (1 Reply)
Discussion started by: omer_ome
1 Replies

10. HP-UX

find files modified in a specific month

hello i need a way to list files modified in a specific month and move them to a specific directry , i mean somthing like : find . -modifiedtime "May" -print -exec /usr/bin/mv newdirectory thank u (1 Reply)
Discussion started by: omer_ome
1 Replies
Login or Register to Ask a Question