13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 9 ■ WORKING WITH TEXT IN FILESIf you want to save it to a file, use this:antiword file.doc > file.txtThat’s no good if you’re looking at something like information from a crash file or a core dump.You may just be able to eyeball it, using cat or a text editor, but this is tough on the eyes.od -c filenameThis will convert bytes to ASCII characters wherever possible, but this is rarely terribly useful,unfortunately. strings is more likely to be helpful. It grabs any ASCII strings it can out of the file it’spointed at.strings filename | lessFor example, you may also be in the position of encountering a random binary file and trying towork out where it came from and what it is or does. Getting any readable text information out of thebinary can be helpful here. If you’re very lucky, you might get help information out of it (try strings/bin/ls | less, and note the help information near the end of the output). To simplify this a bit, youcan pipe the output of strings through grep to look for something specific:> strings /bin/ls | grep -A 5 -n Usage522: Usage: %s [OPTION]... [FILE]...523: List information about the FILEs (the current directory by default).524: Sort entries alphabetically if none of -cftuvSUX nor --sort.525: Mandatory arguments to long options are mandatory for short options too.526: -a, --all do not ignore entries starting with .527: -A, --almost-all do not list implied . and ..The -A 5 option to grep gives five lines of context after the match is found; -n prints the line number.For example, it’s very useful to quickly find out which libraries a particular binary needs:$ strings /usr/bin/latex | grep lib | grep '\.so'The grep '\.so' part is there to restrict the grep lib returns to only those lines that refer toparticular binaries (lib*.so.*) rather than also getting lines such as the error lines from libpng that arereturned on my system! The \ is needed to treat the . as a literal rather than as meaning “any character.”201Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!