1827259 Members
2264 Online
109716 Solutions
New Discussion

Find Command

 
SOLVED
Go to solution
Kavita Poonia
Regular Advisor

Find Command

Hello all,

I want to find out the files under a directory which are modified from past 2 days. Then what syntax should I use with find command.


Is the below format okay .........

find /opt -xdev -mtime 2 -exec ll {} \;

Thanks * regards,
Kavita
5 REPLIES 5
Patrick Wallek
Honored Contributor
Solution

Re: Find Command

If you want all files modified during the last 2 days, then you need to use a '-2'.

find /opt -xdev -mtime -2 -exec ll {} \;

James R. Ferguson
Acclaimed Contributor

Re: Find Command

Hi:

Use this:

# find /opt/ -xdev -type f -mtime -2 -exec ls -l {} +

This limits your search to *files* that have been modified sometime in the last 2-days (where a day is exactly 24-hours). The '-exec' argument is terminated with a "+" instead of a ";". This causes multiple arguments to be passed to your 'ls' greatly reducing the number of forked processes and thereby greatly improving overall performance.

Regards!

...JRF...
Kavita Poonia
Regular Advisor

Re: Find Command

Thanks Patrick and James.........It was really very helpful.......so if I want to see any file which is modified in past x days then I have to specify -x with -mtime......one more thing how can I find a file under a directory which is growing continuously with find command........
Dennis Handly
Acclaimed Contributor

Re: Find Command

>so if I want to see any file which is modified in past x days then I have to specify -x with -mtime

Yes. But it is exact. It will not return files modified exactly 2 days ago or 2.5.
Caution, if you export UNIX95, the dates are completely different.

>how can I find a file under a directory which is growing continuously with find command

This requires you to create a "database" with the size the last time you checked.
Of course, if the file is always being appended, then all you need is that it was modified.
Kavita Poonia
Regular Advisor

Re: Find Command

Thanks Dennis.........