1827460 Members
4228 Online
109965 Solutions
New Discussion

find and -exec

 
Leo The Cat
Regular Advisor

find and -exec

Hi Guys

I'd like to do something like this:

find /su01 -name webutil.plx -exec rm {} \;

but before the erase i'd like to copy the file with the extension .20090220 to have by example the file webutil.plx.20090220.

(Note. copy before because I want a new inode)

How to do this small affair ?

bests Regards
Den
5 REPLIES 5
Steven Schweda
Honored Contributor

Re: find and -exec

> (Note. copy before because I want a new
> inode)

Why? "mv" makes more sense to me than a
copy-and-delete scheme.

If you really want to do two things, you can
use more than one "-exec" clause in one
"find" command.
Dennis Handly
Acclaimed Contributor

Re: find and -exec

>Steven: If you really want to do two things

You can also invoke a script to do what you want. You may want your script to be able to handle multiple files by using a for or while loop.
T G Manikandan
Honored Contributor

Re: find and -exec

you can do something like
* backing up all webutil.plx in a tar and removing them

$tar cvf plx.tar $(find ./ -name webutil.plx) && find ./ -name webutil.plx -ok rm {} \;
T G Manikandan
Honored Contributor

Re: find and -exec

And you can extract from the tar the old files if needed.
Wilfred Chau_1
Respected Contributor

Re: find and -exec

To rename the file from .plx to .20090220 extension.

find /su01 -name webutil.plx |xargs rename .plx .20090220

To rename and create a new plx file.

cd /su01
ls *.plx | awk -F"." '{print $1}' | while read file; do mv ${file}.plx ${file}.02232009; touch ${file}.plx; ls -il; done

ls -i should show a different inode.