Operating System - HP-UX
1819814 Members
3639 Online
109607 Solutions
New Discussion юеВ

Find only Recently Created Files

 
SOLVED
Go to solution
Global Service Desk
Frequent Advisor

Find only Recently Created Files

Hi Guys,

How to find the file which are created recently,


for ex:

i would like to list the files created from past 10 min.

Thanks in advance !!

Best REgards,
GOvindaG.

15 REPLIES 15
Pete Randall
Outstanding Contributor

Re: Find only Recently Created Files

Use the touch command to create a reference file with a time stamp of 10 minutes ago, then use the find command with it's -newer option:

find /dir_name -newer ref_file


Pete

Pete
Arunvijai_4
Honored Contributor

Re: Find only Recently Created Files

Hello,

# find . -type f -ctime -1 -exec ll {} \;

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Robert-Jan Goossens
Honored Contributor

Re: Find only Recently Created Files

Hi,

# touch -t 0601101235 reffile
# find /directory -newer reffile -exec ls -l {} \;

Regards,
Robert-Jan
Muthukumar_5
Honored Contributor

Re: Find only Recently Created Files

You can get it as,

find / -type f -mtime -1 -atime 1 -ctime 1 -print;

We can not specifically get newly created files with default commands informations. Some work around is needed.

--
Muthu
Easy to suggest when don't know about the problem!
Arunvijai_4
Honored Contributor

Re: Find only Recently Created Files

Hello,

Check this thread

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=986260

Read A.Clay's rrply. it is not possible to find out the creation time in Unix only Last modifcation time.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
john korterman
Honored Contributor

Re: Find only Recently Created Files

Hi,

as unix does not itself store information about file creation, I am afraid it is not possible - unless you maintain a database of your own.

- sorry to be the bearer of bad news!


regards,
John K.
it would be nice if you always got a second chance
Muthukumar_5
Honored Contributor

Re: Find only Recently Created Files

A simple was as,

#!/bin/sh

find / -type f > /tmp/filebefore.log
sleep 600
find / -type f > /tmp/filenow.log

diff /tmp/filebefore.log /tmp/filenow.log | | grep -Ev '^[0-9]|filenow'


It is working.

--
Muthu
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Find only Recently Created Files

If you want to find only newly create files within 10 min then use my above method. It is like differntiating previosly available files with current files.

--
Muthu
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Find only Recently Created Files

If you want to find only newly create files within 10 min then use my above method. It is like differntiating previosly available files with current files.

If you search for > then it is new files. Else if < then it is deleted.

--
Muthu
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor
Solution

Re: Find only Recently Created Files


#!/bin/sh

find / -type f > /tmp/filebefore.log
sleep 600
find / -type f > /tmp/filenow.log

echo "Newly created files"
echo
diff /tmp/filebefore.log /tmp/filenow.log | | grep -Ev '^[0-9]|filenow' | grep '>'

echo "Deleted files"
echo
diff /tmp/filebefore.log /tmp/filenow.log | | grep -Ev '^[0-9]|filenow' | grep '<'

PS: May be a problem with browser + refresh, too many replies :(

--
Muthu
Easy to suggest when don't know about the problem!
Arunvijai_4
Honored Contributor

Re: Find only Recently Created Files

Hello,

ll -rtl |grep "`date "+%b\ %d"`"

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Global Service Desk
Frequent Advisor

Re: Find only Recently Created Files

Amazing !!

I really cant belive myself for having soo many replies..

Thanks a lot Guys !! i am really very Happy to see soo many replies..

I hope you have been rewarded with the right points.

But, Sad to know that its not possible to find at one step.

Muthu, thanks a lot for the workarounds.. i will implement this in my EnV and see how it works.

Thanks once again Guys for the Time u spent on this.

Cheers !!
GOvindaG.
Global Service Desk
Frequent Advisor

Re: Find only Recently Created Files

Muthu,

The Workaround what u gave will find the files for the next 10 min, that means if i start the script now i will get the list for the next ten min. but is it possible to get the previous ten min ??


Any More inputs for that ??

Regards,
GovindaG.
Muthukumar_5
Honored Contributor

Re: Find only Recently Created Files

We have to have the all files available in the disk to compare with latest files.

Logic is simple.

Generate a file with all files available at that moment. Generate available files list into new file and compare with first file list.

In this,

# Step 1
# It is having all files in the system
find / -type f > /tmp/filebefore.log

# 10 minute calculataion. May be you can change or remove it.
sleep 600

# To generate files list now
find / -type f > /tmp/filenow.log

Step 1 is most important. Based on the file informations in that only we can compare the new files list.

--
Muthu
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Find only Recently Created Files

Are you going to continue the process of newly created files information then,

#!/bin/sh

find / -type f > /tmp/filebefore.log

while [ 1 ]
do

# Change this time to your need. Presently 10 minutes
sleep 600

find / -type f > /tmp/filenow.log

echo "Newly created files"
echo
diff /tmp/filebefore.log /tmp/filenow.log | | grep -Ev '^[0-9]|filenow' | grep '>'

echo "Deleted files"
echo
diff /tmp/filebefore.log /tmp/filenow.log | | grep -Ev '^[0-9]|filenow' | grep '<'

# To generate new file information
mv /tmp/filenow.log /tmp/filebefore.log

clear

done

## END ###
exit 0

############

It will move recent file informations to old file in,
mv /tmp/filenow.log /tmp/filebefore.log step. If you want to compare always with old file list then comment that line.

It will run like top tool.

--
Muthu
Easy to suggest when don't know about the problem!