If a user encounters a binary file and does not know what it is used for or where it came from, they may gain some insight into its origins and use by searching for character strings within the file. If the cat command is used to view a binary file, the user will get a screen full of garbage that will more often than not change the display characteristics. Instead, the
strings command should be used, as demonstrated in the following examples:
Find All Strings in the Binary File
$ strings echo
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%s (%s) %s
Written by %s.
Again the above output has been abbreviated to save space, but you can see that there is some useful information here. Just knowing that “This is free software” and that it is copyrighted by the Free Software Foundation can give you some great insight on where this came from and why it might be there.
Finding Occurrences of a String in a Binary File
Here we show how the output of the
strings command can be piped into the
grep command to look for specific words within a binary file.
$ strings echo|grep GLIBC
This shows how
grep can be used to limit the output of a command to only lines that contain certain text.