Skip to content

What is strings Linux command?

The strings command in Linux is used to extract printable characters from files. It is commonly used to search binary files for human-readable strings. By default, it displays all strings that are at least four characters long. This command can be helpful in analyzing unknown files or identifying text within binary files.

strings Syntax:

Terminal window
strings [options] <filename>

strings Options:

OptionDescription
-aScan the whole file
-e Select character encoding (default is ASCII)
-n Set minimum string length to display
-t Display non-text strings using specified format

Parameters:

ParameterDescription
filenameFile to extract strings from

strings Command Usage Examples:

Extract Strings from a Binary File

Terminal window
strings /bin/cat

This command extracts printable strings from the binary file “/bin/cat”.

Show Strings Longer Than a Specified Length

Terminal window
strings -n 10 /usr/bin/ls

Displays only the strings longer than 10 characters from the file “/usr/bin/ls”.

Display Strings in a File With Encoding Errors

Terminal window
strings -e l /var/log/syslog

Shows strings in the file “/var/log/syslog” using the “l” encoding to handle encoding errors.

Ignore Short Strings in a File

Terminal window
strings -n 20 /etc/passwd

Ignores strings less than 20 characters in the file “/etc/passwd” and displays longer strings only.

Display Process Memory Strings

Terminal window
strings /proc/1234/mem

Displays strings from the memory of process ID 1234.

How do I use strings in Linux?

To use the strings command in bash, execute the following command:

Terminal window
strings file.txt

How can I limit the string length displayed in Linux?

To limit the string length displayed when using the strings command, you can utilize the -n option followed by the desired minimum string length. Here’s an example:

Terminal window
strings -n 8 file.txt

How to display only strings that match a given pattern in Linux?

To display only strings that match a specific pattern when using the strings command, you can combine it with grep. Here’s an example of how to do this:

Terminal window
strings file.txt | grep "pattern"

How can I get the strings in a specific encoding format in Linux?

To specify the encoding format for the strings command in Linux, you can use the -t option followed by the encoding name. Here’s an example:

Terminal window
strings -t d file.txt

How do I extract strings from multiple files in Linux?

To extract strings from multiple files using the strings command in Linux, you can provide the list of files as arguments. Here’s an example:

Terminal window
strings file1.txt file2.txt file3.txt

How to display the offsets of each string in Linux?

To display the offsets of each string when using the strings command in Linux, you can include the -o option. Here’s an example:

Terminal window
strings -o file.txt

Can I display the printable characters in hexadecimal format with strings in Linux?

Yes, you can display the printable characters in hexadecimal format by using the -a option with the strings command in Linux. Here’s an example:

Terminal window
strings -a file.txt

Applications of the strings command

  • Extracting readable text from binary files
  • Revealing hidden or obfuscated strings within files
  • Finding passwords or sensitive information stored in files
  • Extracting human-readable strings from compiled executables
  • Analyzing malware to uncover its functionality