Operating System - HP-UX
1755083 Members
4668 Online
108829 Solutions
New Discussion юеВ

Re: "scripting and find command"

 
SOLVED
Go to solution
Belinda Dermody
Super Advisor

"scripting and find command"

I am stumped on this one. We have an application that is bombing quite often and one thing that I need to supply to the thech's is a core file. Lately, by the time I transverse through all the subdirectores with my script to report files and file sizes and locate core files, the application will crash again and overwrite the existing core file(If it is the same crash). I have written a script that gives me all the general information while I am on the phone. What I would like is there a way with the find command to rename core file to either core. or core.sav and keep it in the same sub dir as it traverse all the directories.
7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor

Re: "scripting and find command"

Hi:

This one is pretty easy:

find . (or /) -name 'core' -exec mv {} {}.sav \;

If you know the starting directory specify in or use /.

Clay
If it ain't broke, I can fix that.
Belinda Dermody
Super Advisor

Re: "scripting and find command"

Clay, thanks for the quick response, but something is wrong here, I have tried it on my HP systems (10.20) and Suns and I get the same results. I created files named core in /tmp and /tmp/restore.
I run your command find /tmp -name core -exec mv {} {}.sav \; -- What happens is the core files go into the bit bucket in the sky. They are no longer there or core.sav. Any additional assistance would be appreciated, as in the past I will assign points.
James R. Ferguson
Acclaimed Contributor
Solution

Re: "scripting and find command"

Hi James:

You can do this:

# find /tmp -type f -name core|xargs -i mv {} {}.old

If you prefer, you can 'cd' into the directory of your choice and do:

# find . -type f -name core|xargs -i mv {} {}.old

...JRF...
Belinda Dermody
Super Advisor

Re: "scripting and find command"

Thanks Jim, it works like a charm
A. Clay Stephenson
Acclaimed Contributor

Re: "scripting and find command"

Hi,

Sorry about that, James' response is the correct one or you can create a small shell script (/tmp/my.sh) to do this:


mv ${1} ${1}.sav

and then rather
find . -name 'core' -exec /tmp/my.sh {} \;

If you like you could also pass another arg to the script so that you could have .sav1 .sav2 ...

Sorry about that, Clay
If it ain't broke, I can fix that.
Klaus Crusius
Trusted Contributor

Re: "scripting and find command"


The core has been renamed to {}.old !!!
There is a live before death!
Belinda Dermody
Super Advisor

Re: "scripting and find command"

I will give Clay 7 more points as his correction also works, but Jim came up with the first correct procedure. I have tried both ways and they both do the mv to a new name and thanks guys.