Operating System - HP-UX
1833873 Members
2081 Online
110063 Solutions
New Discussion

Re: Help about find command

 
SOLVED
Go to solution
Mauro Gatti
Valued Contributor

Help about find command

Hi all, I must delete all files in directory /a older than 2 days but only files in this directory and not in subdir of /a ( /a/one is to delete but /a/b/two not)

Rreading find man pages i've seen some option like -depth, -prune etc. but i don't understand how can I use it.
Could You help me to understand these options?
Ubi maior, minor cessat!
5 REPLIES 5
Uday_S_Ankolekar
Honored Contributor

Re: Help about find command

Hi

Try this command:
find -mtime +2 |xargs rm -f

-USA


Good Luck..
James R. Ferguson
Acclaimed Contributor
Solution

Re: Help about find command

Hi:

By design, 'find' recursively descends the directory path presented to it.

The '-xdev' (or '-mountstop') option prevents descending mountpoints below the starting path. For example, compare:

# find / -name "*.log"

versus

# find / -name "*.log" -xdev

The '-depth' option allows the files in directories to be processed *before* the directory itself. This is most useful in copies.

Regards!

...JRF...

MANOJ SRIVASTAVA
Honored Contributor

Re: Help about find command

Hi Mauro


I dont use find but use awk to do this , to get the list of files like this


ls -l | awk '{if ($6=="May" && $7=="6") print $NF}' > test

the test file will have list of files created for May 6th . You can be more creative with awk as you can use >,<,= in the arguments .

Then you can use test file as an argument to delete ,etc


Manoj Srivastava
S.K. Chan
Honored Contributor

Re: Help about find command

/a older than 2 days but only files in this directory and not in subdir of /a ( /a/one is to delete but /a/b/two

You can do this ..
# cd /a
# find . \( -name b -prune \) -o -mtime +2 -exec rm -f {} \;

The above will exclude dir /a/b from the search. Test it first with some other action like "ll {} \;" before running the actual remove.

Helen French
Honored Contributor

Re: Help about find command

Hi Mauro:

This thread may help you:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xcfd194f22a31d6118fff0090279cd0f9,00.html

HTH,
Shiju

Life is a promise, fulfill it!