script to delete files

hi guys,

i need a script to delete files that have core in their name ...it might be part of the file name or as a .core extension ...any file that has core as its extension....

i am only able to delete files which just have thier name as core

using this :

find $1 -type f -name "core" -exec rm -f {} \;

i am passing the directory to look for a a command line argument...

can anybody help me with this please....????

You were almost there my friend

find $1 -type f -name "*core*" -exec rm -f {} \;

Cheers,
K

thx man!! Hey by the way there is another thing with the core files which i describe below...

How would i do this!!!!

check if the fileexists in that directory by using the conditional statement

if [[ -f filename ]]
then
     remove core
else
     warn user that the file does not exist # optional - depends on your requirement
fi

Hope this helps.

Cheers,
K

Hey buddy,
Thx a lot!!
I got the test part but i am unable to understand the full meaning of the problem....

which filename ur refering to in the test case...???Can u explain wht does the whole problem asks to do...?

is this a homework ???:wink:

no man its not homework!!!!i wanted to learn it ....as it will be useful for my work because i am mainly a windows person...my office has told me to learn linux.....its part of my learning thing!!!

Ok no problem, even i have gone through this. A unix resource, was asked to work on Visual Basic too which i did but still hate it.

Anyways back to your problem.

Basically you need to know what the system path is ( i hope it is declared as an environment variable some where) and then search for the file at that path.

So check for the executable filename at the specified path, if exists delete the core.

if [[ -x $SYSPATH ]]
then
     find $1 -type f -name "*core*" -exec rm -f {} \;
fi

Hope i am clear this time.

Cheers,
K

hey buddy,

i know sometimes man work sucks...
i got what ur saying...but what is the significance of the system path with relation to the core file....

and which core file will it delete ????will it delete the core files in the directory i specify......????

you probably have to use "file core" to find out what caused the crash

LOL
you don't happen to be at RMIT ?
i think the office told everyone to learn this

Nah Man!!! i wish i was in College...!!!are u in RMIT...??a lot of my mates are in RMIT..!!!

ya buddy i will try it out...!!!