Operating System - HP-UX
1822000 Members
3764 Online
109639 Solutions
New Discussion юеВ

find command: replace exec to xargs problem

 
Ho_5
Advisor

find command: replace exec to xargs problem

Hi,

I want to replace the exec to xargs in find command, because every time when I run the command CPU is overloaded.

find . -name "*.day.*" -exec cp -r {} /store \; -exec rm -f {} \;
13 REPLIES 13
Pete Randall
Outstanding Contributor

Re: find command: replace exec to xargs problem

I'm not sure how you would chain the two commands together without repeating the find, but using find with xargs is easy:

find . -name "*.day.*" |xargs cp -r;find . -name "*.day.*" |xargs rm -f


Pete

Pete
Ho_5
Advisor

Re: find command: replace exec to xargs problem

thanks, but it should not work

I try to change it into the next syntax, but the CPU load still HIGH.

find . -name "*.day.*" | xargs -i cp -r "{}" /store | xargs -i rm -f

By the way, do I need to use -i and "{}"???

Regards,

John
Pete Randall
Outstanding Contributor

Re: find command: replace exec to xargs problem

I'm curious - does running the find command by itself increase your CPU load?

find . -name "*.day.*"


Pete

Pete
John Poff
Honored Contributor

Re: find command: replace exec to xargs problem

Hi,

How many files and directories are in the directory tree at the point where you run the find command?

JP
Ho_5
Advisor

Re: find command: replace exec to xargs problem

The problem is on every half of hour there are two find command's in two different scripts running.
It looks like running 2 find command in the same time, it will generate CPU overload.
Reschedule the scripts in the crontab is not possible.
So any idea how to rebuild the find command??
Ho_5
Advisor

Re: find command: replace exec to xargs problem

more than 100 hundred at least..
Robin Wakefield
Honored Contributor

Re: find command: replace exec to xargs problem

Hi

How about trying:

find . -name "*.day.*" | xargs -i echo "cp -r {} /store;rm -f {}" |sh

rgds, Robin.
David_246
Trusted Contributor

Re: find command: replace exec to xargs problem

Hoi Ho,

Why don't you do the following :

for i in `find ./ -name "*.day.*"`
do
cp -r $i /store
rm -f $i
done

Groeten/Regs,
David
@yourservice
David_246
Trusted Contributor

Re: find command: replace exec to xargs problem

Uhh,

What about :

find ./ -name "*.day.*" -exec mv {} /store \;

Regs David
@yourservice
Ho_5
Advisor

Re: find command: replace exec to xargs problem

hmmmm mv command.

find ./ -name "*.day.*" -exec mv {} /store \;

If I translate it into xargs. should it be like this??

find . -name "*.day.*" | xargs -i mv ./{} /store/{}

The advantage of using "xargs" instead of "exec" is that it save the CPU time or not? if you have a lot of file to find. please confirm this

John
James R. Ferguson
Acclaimed Contributor

Re: find command: replace exec to xargs problem

Hi Ho:

The advantage to 'xargs' over 'exec' in situations like you describe is really two-fold. First, you avoid the potential for an "argument list too long". Secondly, and more importantly, you avoid forking a separate task for every argument processed.

Another often overlooked ability of 'xargs' to bundle, as many arguments as specified by its '-n number' option together into a single execution.

Regards!

...JRF...
Donny Jekels
Respected Contributor

Re: find command: replace exec to xargs problem

there,

this works.

find ./ -name \*.day.\* -exec /usr/bin/mv {} /store \;
"Vision, is the art of seeing the invisible"
John Bolene
Honored Contributor

Re: find command: replace exec to xargs problem

find is a pig no matter what you do with it

it has to traverse the I/O super block tables and find what you are looking for

you can nice this process so that it gets whatever cpu is left over

you can cd to the directory you are finding stuff in and then do the find

you have to find (pun intended) ways to reduce the number of I/O trees that the command is searching thru to find what you want
It is always a good day when you are launching rockets! http://tripolioklahoma.org, Mostly Missiles http://mostlymissiles.com