Wednesday, October 15, 2008

'B core file'

Hi

This is what i have read in the book A practical guide to ubuntu Linux

sudo find / -type f -name core | xargs file | grep 'B core file' | sed 's/:ELF.*//g' | xargs rm -f


The find command lists all ordinary files named core and sends its output to xargs,which runs file on each of the files in the list. The file utility displays a string that includes B core file for files created as the result of a core dump. These files need to be removed. The grep command filters out from file any lines that do not contain this string. Finally sed removes everything following the colon so that all that is left on the line is the pathname of the core file; xargs then removes the file.

can any one explain me what exactly is meant by the string/search pattern 'B core file' ?

pinniped

You're looking for the string 'B core file'.

a. 'find' looks for any file named 'core'
b. 'xargs' generates a 'file /path/to/nth/core' list to process
c. 'grep' finds the string 'B core file' which essentially identifies each file named 'core' which is actually a core dump
d. 'sed' strips the string
e. 'xargs' takes the result of the sed part and uses it to create a command line to delete the offending file.

For example, I used 'ulimit' to allow a core dump, made a busy-loop program, ran it, and sent it a SIGSEGV to get a file named 'core'. Now doing "file core" gives me:

core: ELF 64-bit LSB core file x86-64, version 1 (SYSV), SVR4-style, from './a.out'

Note that 'B core file' matches "LSB core file" in the result from 'file'.

That 'sed' part is doing nothing on my machine using that output though - the sed command is a global substitution which is meant to remove a string - but I'm no sed expert so I don't know what's going wrong.

[edit] OK, OK - it's obvious that 'sed' should strip the colon and all other text following 'core' in that example line above. To limit accidental matches, a wider pattern is used ": ELF.*" which means "match ': ELF' and everything which follows". SO, in your post you're leaving out that very important space between ':' and 'ELF'.

No comments:

Post a Comment