Start with a byte filter, not a decoder
strings scans a file, or standard input when no file is named, and prints runs of displayable characters. GNU strings defaults to runs at least four characters long. It does not understand what a URL, password, symbol, or error message means; it only finds bytes that satisfy its current display and encoding rules.
Work in a directory where you may create a strings-demo subdirectory. mkdir creates it, each && runs the next command only after success, and cd enters it. printf interprets the trusted format: the octal escape \177 writes byte 7f and \0 writes a zero byte. The shell's > redirection creates sample.bin, replacing that pathname if it exists. The printf article develops the format-and-data boundary.
The default scan omits ELF and ok because they contain only three and two displayable characters. It prints the two longer runs and removes the zero bytes that terminated them. The result is a view, not a copy of the file.
mkdir strings-demo &&
cd strings-demo &&
printf '\177ELF\0api.example.test\0ok\0cache-ready\0' > sample.bin &&
strings sample.binapi.example.test
cache-readyThis article tests GNU strings from Debian Binutils 2.44. GNU Binutils 2.47, released July 26, 2026, is the current upstream release at review time; distribution versions and defaults may differ.
Keep offsets and choose the threshold
The -n option takes the minimum run length in characters. -n 2 admits the short ok run and the three-character ELF run. Smaller thresholds increase recall, but they also produce more coincidental noise.
The -t option takes one radix letter and prints each run's starting file offset: x means hexadecimal, d decimal, and o octal. Here 1, 5, 16, and 19 are hexadecimal offsets. They are locations in sample.bin, not virtual memory addresses. The od article shows the underlying bytes when an offset needs independent confirmation.
Offsets turn a fragment into a reproducible lead. Record the exact file hash and tool settings too: a changed threshold, encoding, or input changes the evidence view.
strings -n 2 -t x sample.bin 1 ELF
5 api.example.test
16 ok
19 cache-readyGNU also accepts the older -NUMBER spelling for the minimum length. Prefer -n NUMBER because its argument is visible and the form is easier to distinguish from a cluster of flags.
Decide whether object-file structure is trusted
GNU -a, also spelled --all, scans every byte. GNU -d, or --data, asks the Binary File Descriptor library (BFD) to parse a recognized object and scan only initialized, loaded data sections. -d may reduce noise, but it can omit useful bytes in nonloaded sections.
The setup compiles a tiny ELF program, then objcopy adds a nonloaded .review section containing WHOLE_ONLY. gcc and objcopy are prerequisites for this fixture, not features of strings. grep -E keeps only either named marker; -E enables the two-alternative extended regular expression separated by |. The grep article explains alternation and the difference between a filtered view and the original stream.
The full scan finds both markers. The data-section scan finds only DATA_VISIBLE. More importantly, the GNU manual warns that -d exposes strings to security flaws in BFD's object parser. Use -a for the smaller parsing surface when the object structure is untrusted, and inspect hostile binaries in an appropriately isolated environment. The upstream security policy treats input trust as an explicit boundary; this is risk guidance, not a claim that this fixture exploits a CVE.
printf 'const char loaded[] = "DATA_VISIBLE";\nint main(void){return loaded[0] == 0;}\n' > app.c &&
printf 'WHOLE_ONLY\0' > note.bin &&
gcc -O0 -o app app.c &&
objcopy --add-section .review=note.bin --set-section-flags .review=readonly app app.review &&
strings -a app.review | grep -E 'DATA_VISIBLE|WHOLE_ONLY' &&
strings -d app.review | grep -E 'DATA_VISIBLE|WHOLE_ONLY'DATA_VISIBLE
WHOLE_ONLY
DATA_VISIBLEGNU builds can be configured with either full-file or data-section scanning as the default. Spell out -a or -d when the distinction matters instead of inheriting a packaging choice.
Preserve filenames across a collection
A list of fragments without provenance is easy to misread. -f, the short form of --print-file-name, prefixes every extracted run with its source pathname. -n 6 suppresses shorter noise.
find selects regular files below samples. Its -exec action runs strings with as many selected pathnames as fit in each invocation; the terminating + belongs to find, not strings. LC_ALL=C gives sort a stable bytewise order for this transcript. The find article explains selection versus action, and the sort article develops locale-sensitive ordering.
The values are deliberately synthetic. A real token-like fragment is a lead to validate through the owning format or application, not proof that the value is live, secret, or reachable.
mkdir samples &&
printf '\0service-token=DEMO_ONLY\0' > samples/a.bin &&
printf '\0build-id=20261125\0' > samples/b.bin &&
find samples -type f -exec strings -f -n 6 {} + | LC_ALL=C sortsamples/a.bin: service-token=DEMO_ONLY
samples/b.bin: build-id=20261125Filenames can contain newlines and strings output is line-oriented by default, so -f is not an unambiguous machine protocol for arbitrary pathnames. Use a language API or a separately encoded manifest when exact automated attribution is required.
Select code-unit width and byte order
The default GNU encoding s scans single 7-bit byte characters. The -e option selects a different code-unit width and byte order. l means 16-bit little-endian and b means 16-bit big-endian; uppercase L and B select 32-bit units, while S accepts single 8-bit bytes.
The fixtures spell WIDE as 16-bit code units in opposite byte orders. The default scan sees printable letters separated by zero bytes, so no four-character run exists. -e l and -e b each recover the matching representation.
This option is a byte-layout hypothesis, not full Unicode decoding. It does not validate normalization, surrogate pairs, language, or semantic meaning. Record the encoding choice beside any reported offset.
printf 'W\0I\0D\0E\0\0\0' > little.bin &&
printf '\0W\0I\0D\0E\0\0' > big.bin &&
printf '%s\n' 'default scan:' && strings little.bin &&
printf '%s\n' 'little-endian:' && strings -e l little.bin &&
printf '%s\n' 'big-endian:' && strings -e b big.bindefault scan:
little-endian:
WIDE
big-endian:
WIDEGNU's --unicode option separately controls treatment and rendering of UTF-8 multibyte sequences. That extension is not the same mechanism as -e l or -e b, and it is not a portable BSD interface.
Render suspicious Unicode visibly
A readable filename fragment can contain a Unicode control that changes how surrounding text is displayed. GNU --unicode=escape recognizes UTF-8 multibyte sequences and renders them as escape notation instead of applying their visual effect. It also enables the single-8-bit-byte scan needed to keep the UTF-8 sequence together.
The fixture places U+202E, RIGHT-TO-LEFT OVERRIDE, between safe- and -txt.exe. The shell's octal byte escapes create the UTF-8 encoding without placing the control in this article. Output shows \u202e literally, so the hidden direction change becomes reviewable.
Escaping UTF-8 does not make every byte stream safe or establish intent. In particular, --unicode=escape is a display mode, not strict UTF-8 validation or canonicalization. Preserve the original bytes and use a strict validator when validity or canonical identity matters; use a byte viewer for controls and malformed encodings, and avoid pasting unreviewed output into terminals, tickets, or logs that interpret control sequences.
GNU Binutils Bug 34902, reported October 27, 2026, records that strings can accept malformed UTF-8 in its Unicode handling. At review time the official issue is open and unconfirmed, with no assigned CVE or documented fix. The example here demonstrates safe rendering of a valid control character and deliberately does not reproduce malformed input.
printf 'safe-\342\200\256-txt.exe\0' > suspicious-name.bin &&
strings -n 3 --unicode=escape suspicious-name.binsafe-\u202e-txt.exeGNU also offers locale, hex, and highlight display modes. Escape mode is useful for a plain-text report because its result does not depend on terminal color support.
Do not assume one output line is one string
GNU normally includes tabs and spaces inside a run but treats newline and carriage return as terminators. -w, or --include-all-whitespace, makes all whitespace eligible, so one extracted string may span several output lines. --output-separator supplies text between completed runs.
od displays the resulting bytes. The first extracted run contains the original newline between alpha and beta. The literal |END| separator follows that run and gamma. There is no final newline because the chosen separator does not contain one.
A visible separator is not collision-proof: the input may contain the same bytes. Do not parse line counts, grep hits, or separator text as reliable record boundaries after -w unless a higher-level contract makes collisions impossible.
printf 'alpha\nbeta\0gamma\0' > whitespace.bin &&
strings -w --output-separator='|END|' whitespace.bin |
od -A n -t x1c -v 61 6c 70 68 61 0a 62 65 74 61 7c 45 4e 44 7c 67
a l p h a \n b e t a | E N D | g
61 6d 6d 61 7c 45 4e 44 7c
a m m a | E N D |The od article explains -A n, -t x1c, and -v. Here x1c deliberately shows each byte in hexadecimal and as a character or escape.
Use fragments to triage, then verify
During incident response or an authorized assessment, strings can quickly surface configuration names, URLs, build paths, error messages, and credential-shaped text. The safe sequence is extract to a protected artifact, retain provenance and offsets, search that artifact, and verify interesting bytes against the original format.
umask 077 removes group and other permissions from subsequently created files. -a avoids object parsing, -t x records offsets, and -n 8 reduces short noise. grep -Ei performs a case-insensitive extended-regex search for token, password, secret, or BEGIN. The synthetic value is not a real credential.
A hit may be dead code, test data, a key name without its value, or random bytes. A miss is equally weak: text may be compressed, encrypted, encoded differently, generated at runtime, split by control bytes, or removed when a binary was stripped. strings is a triage instrument, not a malware verdict or secret scanner.
printf '\0DB_PASSWORD=not-a-real-secret\0ordinary-message\0' > supplied.bin &&
umask 077 &&
strings -a -t x -n 8 supplied.bin > supplied.strings &&
grep -Ei 'token|password|secret|BEGIN' supplied.strings 1 DB_PASSWORD=not-a-real-secretThe artifact itself may now contain sensitive fragments. Apply the same retention, access-control, and deletion rules as the original evidence; do not attach it casually to a ticket.
Remember that archives hide member boundaries
An archive is another byte container. ar creates bundle.a from two tiny members; ar t lists the member names. strings -f prefixes the container name, while -t x reports offsets in the archive file. It does not identify which archive member supplied each fragment.
grep keeps the two MEMBER_ lines for a stable transcript. The offsets 45 and 8d are hexadecimal positions in this generated archive. To establish membership, list or extract the archive with a format-aware tool in a disposable directory, then scan the members separately.
This limitation also applies to packed, compressed, and filesystem-image formats: strings sees only the bytes presented to it. Format-aware unpacking can reveal more, but it also increases parser exposure and must respect the trust boundary.
printf '\0MEMBER_ONE\0' > one.bin &&
printf '\0MEMBER_TWO\0' > two.bin &&
ar rcs bundle.a one.bin two.bin &&
ar t bundle.a &&
strings -f -t x bundle.a | grep 'MEMBER_'one.bin
two.bin
bundle.a: 45 MEMBER_ONE
bundle.a: 8d MEMBER_TWOGNU ar defaults to deterministic metadata on this system, which keeps these offsets reproducible. Other archive options or longer member names change the container layout and offsets.
Reject plausible partial output
With multiple operands, GNU strings 2.44 diagnoses a missing file, continues with a readable file, emits its fragments, and exits nonzero. A consumer that accepts standard output without checking status can mistake an incomplete scan for a complete inventory.
The parentheses create a subshell for the expected failure. Standard output goes to partial.txt; 2> sends file descriptor 2, standard error, to strings.err. $? expands to strings' immediately preceding status, and printf records it before cat displays both files.
Diagnostic wording varies by version and locale, so automation should test status rather than match this English line. In a pipeline, enable an appropriate pipefail policy or capture component statuses; a successful grep does not prove that strings opened every operand.
printf '\0VISIBLE_OK\0' > readable.bin &&
(
strings missing.bin readable.bin > partial.txt 2> strings.err
printf 'status=%s\n' "$?"
cat strings.err
cat partial.txt
)status=1
strings: 'missing.bin': No such file
VISIBLE_OKTreat the artifact as failed when any required input could not be scanned. Publish it only after the complete command succeeds and its provenance list matches the intended inputs.
State the implementation and evidence claim
POSIX specifies a smaller strings interface than GNU Binutils, and BSD implementations expose different option sets and printable-character rules. GNU extensions in this article include -d, -e, -f, -w, long options, output separators, and Unicode display modes. Check strings --version and the deployed manual before making their output a machine contract.
For each result, record the input hash, implementation and version, full command, locale, encoding, minimum length, scan scope, and offset radix. Preserve the original file. A fragment supports the narrow claim that this configured scan found a displayable byte run at a location; semantic conclusions require a parser, disassembler, application context, or corroborating evidence.
Use strings when a fast, low-assumption view will guide the next question. Do not let familiar words turn a byte-filter result into a story the file has not proved.
The current GNU manual explicitly warns that -d invokes BFD parsing and its possible security flaws. The safer full-byte scan is still not a sandbox: isolate processing of untrusted files according to the upstream security policy and local incident-response controls.