how to delete core file (file created due to apps crashed)

  1. The problem statement, all variables and given/known data:

When looking for corefiles, include any file with core in its name. (Some UNIX/Linux systems add the PID of the process that created the core to reduce the chances of overwriting an already existing core file that might be needed. The above criterion may be just a bit too inclusive, so use the file command to make sure it really is a core file. Now add an additional command line argument -c to the core deletion that you should attempt to add a test that looks for the relevant executable file using a system path, and only deletes the core if the program that crashed is in the path. A program that the user is developing would probably not be in the path and the core file would be retained. This is probably beyond many of your abilities right now. So, the following command will extract the name of the binary which generated the core file :

find . -name core | xargs file | grep "core file" | sed -e �s/^.*from\ //� -e s/\�//g

This is one of many possible starting points to solve the problem. If you have a more succinct way of solving the problem, by all means use it. Note: This only pulls the name of the command from the core, you�ll still need to determine if the binary is in the default path. I have put a sample �real� core file in the directory: /public/courses/UnixEssentials/Assignments/A1 to use for testing.

The requirement here simply asks to find the core file generated by the system binary which has crashed and delete those core file. If the code found a core file generated by a user program, it will ignore it.
2. Relevant commands, code, scripts, algorithms:

find . -name core | xargs file | grep "core file" | sed -e �s/^.*from\ //� -e s/\�//g

as far as I know, the command above will list the name of the binary that generated the core file.

  1. The attempts at a solution (include all code and scripts):
find . -name core | xargs file | grep "core file" | sed -e �s/^.*from\ //� -e s/\�//g

as far as I know, the command above will list the name of the binary that generated the core file.
the general steps for solving the problem is
using the above code line to find the core file generated
distinguish the core file generated by the system and the core file generated
by the user program
if the core file generated by the system, delete it, otherwise, leave it intact
I just don't know how to implement this. Please help me, thank u!

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    FPT Aptech, Ho Chi Minh city, Vietnam, Nguyen Van Hung, cosc2124

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

The above command also gives the signal which triggered the core dump.
Examples from my unix system:

Try it on your course sample core files and see what output you get.

I guess that the "sed" can be adjusted to just give the name of the program which caused the core dump. Then it is a case of finding out if the command is in your current path (possibly with the "whence" command but it depends on what Shell you are using).

Be careful. There is a trick in these instructions. If you only use the supplied command you will never find out the name of the core file and therefore not be able to delete the file. Be careful that you don't end up deleting the program which caused the core dump rather than the core dump itself.

Hint: Try the supplied command without the "sed", then consider how to extract the core file name and the name of the command which caused the core dump.

More hint: When you try with filenames like "core*" in the root partition make sure that your "find" includes "-type f" and that you correctly identify a file as a core dump. Many systems include a directory called "core" and most have "man" pages related to "core" - all of which are files which you definitely don't want to delete.

can u explain for me step by step of what I should do? what basic information I should search to complete those steps? I'm completely new to unix scripting and this is my first assignment. I have completed the other 3 questions, this one is the hardest one that I have no idea of what i should do. I dont even understand your reply, I'm new to this stuff. please help me, thank u

methyl did exactly that in his reply (and very well so, i might add).

Seems like you haven't mastered the basics and this is somewhat advanced stuff. You might consider learning the basics first, but teaching someone UNIX basics over the net would be beyond the scope of this forum. You might want to go to our book recommendation page and read some basic books on UNIX.

I hope this helps.

bakunin

If a pipeline is too complex, study it step by step. For example, run each of these commands. Understand what output it supplies. Once you get it, move on to the next.

find . -name core 
find . -name core | xargs file 
find . -name core | xargs file | grep "core file" 
find . -name core | xargs file | grep "core file" | sed -e 's/^.*from\ //' -e s/\'//g

thanks to all of you.
so far I have understood the following point.
the line file in `find $dval -name core | xargs file | grep "core file" | sed -e 's/^.*from\//' -e s/\'//g` will return the name of the binary that generated the core file.
I have run the command and what it returned is a name of a binary eg. file1 without any path.
I reckon that I have to compare this name with all the names of the binary in all the paths presents in variable PATH of the environment.
If the 2 names match, then the core file should be deleted.
basically that's what I should do, but I don't know how to do the comparision, could you guys give me an example. the difficulty is that the PATH variable will return a whole bunch of paths separated by colon. does this have something to do with IFS? could u give me example? please!
then after the comparison, how do I delete the core file instead of the binary that generated the core files? what scheme should I use?
I'm completely new to this stuff, please help me
thank u

Which Operating System and version are you running?

uname -a

Which Shell are you using?

echo $SHELL

What output do you get from this sample Shell command to find out whether "ls" is in the current PATH ? If you have a modern Shell it should work.

whence ls