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.
How to check strings version in Ubuntu
To check the version of this tool, utilize the below-given command:
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:
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:
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:
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.
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:
Execution of the command will show you the following output:
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:
Execution of the given command will show you the following output:
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:
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:
To get help with strings command, execute the below-given command in your terminal:
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.