Checking a binary or executable file for extracting human-readable text is not something that we do in our day-to-day life, but what if you are asked for it? In Ubuntu, the “stringscommand allows you to see all the human-readable characters present in a binary/executable file. The “strings” command is primarily used to determine the type of file, but it can also be utilized to extract text. For example, you have a file saved in an unusual binary format; you can extract the text you entered in this file using the “stringscommand without encountering non-printable characters.

A question can come to your mind: why do we add text in the executable files? Many developers packaged the binary files when software or application is released. However, it is an excellent idea to include ASCII text in that binary file. It is beneficial for the developers and users to gain a better understanding of the executable file. As a result, the “strings” command will help them determine the content of these non-text files.

In this article, we will talk about how to install and use strings on your Ubuntu system. So, let’s move ahead!

How to install strings in Ubuntu

Firstly, you have to install the “binutils” package for using the “strings” command on Ubuntu. This package has various programming tools for creating and managing binary files, profile data, libraries, object files, and assembly source code.

 $ sudo apt install binutils

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/1-43.jpg" data-lazy- height="334" src="data:image/svg xml,” width=”741″>

How to check strings version in Ubuntu

To check the version of this tool, utilize the below-given command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/2-41.jpg" data-lazy- height="314" src="data:image/svg xml,” width=”737″>

How to use strings command in Ubuntu

The primary usage of the strings command is to extract strings. For that, you will enter the file name as input and run this command in your Ubuntu terminal. In our system, we have a binary/executable file named “samplefile”. We will use this binary file in all our examples.

The strings command will extract all strings present in our specified file. Now, execute the below-given command to check its working:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/3-40.jpg" data-lazy- height="485" src="data:image/svg xml,” width=”737″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/4-37.jpg" data-lazy- height="484" src="data:image/svg xml,” width=”740″>

How to set minimum string length in strings command

In the strings command, the default value of minimum string length is set to 4, which means that this command will only print out the sequence of the characters having a minimum length of 4. You can modify this limit value by utilizing the “-n” option in the strings command. This “-n” option needs a numerical value that represents the limit of the strings.

We have set 3 as the minimum length of strings in the below-given example. Execution of this command will print out the strings having a minimum length of three characters:

$ strings -n 3 samplefile

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/5-36.jpg" data-lazy- height="484" src="data:image/svg xml,” width=”738″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/6-32.jpg" data-lazy- height="483" src="data:image/svg xml,” width=”739″>

How to print offset of a character sequence with strings command

In the strings command, you can utilize the “-t” option for showing the offsets of character sequences. This option requires you to input a single character that defines the radix of the offset. You can use:

  • d” for decimal
  • x” for hexadecimal
  • o” for octal

Now, write out the below-given command for printing out the decimal offset of the strings of your executable file:

$ strings -t d samplefile

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/7-31.jpg" data-lazy- height="484" src="data:image/svg xml,” width=”739″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/8-26.jpg" data-lazy- height="482" src="data:image/svg xml,” width=”737″>

How to scan a complete file with strings command

The “strings” command may or may not scan the entire input file because it depends on its configuration. Utilize the “-a” option to ensure that the strings command scans a complete binary file present in your system.

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/9-24.jpg" data-lazy- height="487" src="data:image/svg xml,” width=”740″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/10-23.jpg" data-lazy- height="485" src="data:image/svg xml,” width=”739″>

How to change the default separator in the strings command

From the above-given example, you can see that the default separator for strings is the new line. You can utilize the “-s” option in the strings command for changing these settings. For instance, we will specify “” as a strings separator in this command:

$ strings -s samplefile

Execution of the command will show you the following output:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/11-19.jpg" data-lazy- height="405" src="data:image/svg xml,” width=”737″>

How to search multiple files with strings command

Wildcards are utilized for searching for specific files. The “*” character represents multiple values in the strings command, and “?” is used to specify a single value. We will search all binary files present in the “/bin” directory using the “*” wildcard in the following example. Here, we have also used the “-if” option because the strings command will list out the extracted result from multiple binary files with the file name present at the start of each line.

Another functionality of the below-given strings command is that it will redirect the extracted result to the “grep” command using the “[|]” pipe operator. This part of the command will look for the strings having the “Copyright” word:

$ strings -f /bin/* | grep Copyright

Execution of the given command will show you the following output:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/12-16.jpg" data-lazy- height="484" src="data:image/svg xml,” width=”737″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/13-14.jpg" data-lazy- height="482" src="data:image/svg xml,” width=”735″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/14-13.jpg" data-lazy- height="484" src="data:image/svg xml,” width=”737″>

How to search in system RAM with strings command

The strings commands can also be used for various other operation apart from extracting strings from binary and executable files. It enables us to check the RAM in our system. For that, the sudo privilege is required since we are accessing “/dev/mem” which contains the blueprint for our system’s main memory. The “less” is used to limit the output of this strings command:

$ sudo strings /dev/mem | less

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/15-15.jpg" data-lazy- height="307" src="data:image/svg xml,” width=”735″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/16-11.jpg" data-lazy- height="485" src="data:image/svg xml,” width=”733″>

How to open manual of the strings command in Ubuntu

If you want to check the manual of strings command, then write out this command in your Ubuntu terminal:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/17-7.jpg" data-lazy- height="314" src="data:image/svg xml,” width=”736″>

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/18-7.jpg" data-lazy- height="576" src="data:image/svg xml,” width=”737″>

To get help with strings command, execute the below-given command in your terminal:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/08/echo/19-6.jpg" data-lazy- height="574" src="data:image/svg xml,” width=”739″>

Conclusion

If you want to check the content of a binary file, then in Ubuntu “strings” command is used. It extracts text fragments from the binary files which are also known as “strings”. This article demonstrated to you how to use the strings command in Ubuntu. We have also explained various examples related to it. Try them out to have a better understanding of the strings command.

About the author

<img alt="" data-lazy-src="https://secure.gravatar.com/avatar/c73b74cd8044d2e9b300610f5af77d0b?s=112&r=g" data-lazy- height="112" src="data:image/svg xml,” width=”112″>

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.