Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any linux command to extracts all the ascii strings from an executable or other binary file? I suppose I could do it with a grep, but I remember hearing somewhere that such a command existed?

share|improve this question
up vote 49 down vote accepted

The command you are looking for is strings

Its name is quite self-explanatory, it retrieves any printable string from a given file.

man strings gives:

STRINGS(1)

NAME
strings - find the printable strings in a object, or other binary, file

SYNOPSIS
strings [ - ] [ -a ] [ -o ] [ -t format ] [ -number ] [ -n number ] [--] [file ...]

share|improve this answer
    
That is exactly what I was looking for, thanks. – Ethan Heilman Aug 7 '09 at 15:27

The command does exist, and is called.... strings!

share|improve this answer

The od command can do this:

od -c *filename*
share|improve this answer
3  
yeah, that does extract the ASCII characters, but it's not really the strings, per se. I think that 'strings' is more useful for the majority of cases. – user5336 Aug 7 '09 at 15:07
    
Ya, didn't know about that command, but I do now! AlberT got my '+1' :-) – Kyle Brandt Aug 7 '09 at 15:20

The strings command is the way to go for this particular type of problems. Sometimes you also have to pipe it out to grep.

For example:

strings somebinaryfile | grep textuwanttofind
share|improve this answer

A problem with using strings is that you don't see surrounding non printables and you have to be careful with the minimum string length.

A problem using

od -c FILE
or
hexdump -C FILE
is that a sequence can be difficult to find if it wraps a line.

Something I like a lot for this is ZTreeWin running in WINE on Linux - you can do a lot with it but the searching in any file or editing binaries can be particularly useful.

The awesome ytree package is available for many Linux and Unix variants and has a good Hex dump view of any file but doesn't have the search that ZTreeWin (and its 16bit predecessor, XTree) have.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.