The grep command searches for strings in text files. However, not only text files contain ASCII 1
characters. Binary files such as executables may contain strings in human-readable text. 2
In the compilation process ascii characters are embedded into the binary files and sometimes, when 3
an application is deployed, some ASCII text is packed into the binary file by the developer. 4
This contains useful information about the binary, like a short help or copyright information. 5
There are also binary files used by different applications that embed sensitive information 6
as credentials.The strings command extracts printable characters from binary files. 7
It prints out character sequences that are at least 4 characters along. Let's see the printable characters 8
from the ls command. First I want to see its path: which ls and strings /bin/ls 9
These are the ASCII characters embedded into ls. 10
I'll use pipe and less to navigate through the output, so | less 11
And I'm searching for the string help. 12
I'm pressing n to see the next occurrency. 13
OK, and I found the help of the command embedded into the command itself. 14
I could also print out ASCII characters from the device file that represents a disk partition. 15
Let's see the partition that is mounted on the root directory. 16
This is the partition, it's /dev/sda5 and I run the the command as root: sudo string -a 17
and the file. 18
I am printing all characters on the partition using the low level device file. 19
It's printing all ASCII characters, -a the options scans the whole file, which is in most cases, 20
the default behavior. 21
I'm interrupting it by pressing control and c. And the last example, which I find interesting, is 22
to search directly into the machine physical memory: ls -l /dev/mem 23
This is a character device file that is an image of the main memory of the computer and strings/dev/mem 24
| less 25
I've got a permission denied error because only root can search into the computer's memory. 26
I'm using sudo before the command's name. 27
These are the printable characters in the physical memory. 28
It's the computer's memory. 29
Interesting, isn't it? 30
There are other options available and you can find them in the man page.