STRINGS(1P)

πŸ’– STRINGS(1P) β€” POSIX Programmer's Manual πŸ’–

okay bestie, come sit with me, we're doing strings today and honestly? it's giving ✨forensics✨. this one's from the POSIX Programmer's Manual, fr fr, and we're gonna go through the whole thing together. no skipping. i will know if you skip. 🫢


🌸 PROLOG 🌸

okay so first things first, a little disclaimer the manual hits you with: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ (so like, consult the corresponding Linux manual page for the details of Linux behavior, bestie), or the interface may literally not be implemented on Linux at all. 😭


πŸŽ€ NAME πŸŽ€

strings β€” find printable strings in files πŸ‘‘


✨ SYNOPSIS ✨

strings [-a] [-t format] [-n number] [file...]

πŸ¦‹ DESCRIPTION πŸ¦‹

so what does it actually DO? the strings utility shall look for printable strings in regular files and shall write those strings to standard output. and what even IS a printable string, you ask? it's any sequence of four (by default) or more printable characters terminated by a <newline> or NUL character. four! by default! remember that number, it comes back. 🌟

additional implementation-defined strings may be written β€” so like, more might show up, it's a vibe, check localedef for the deets.

⚠️ okay important: if the first argument is -, the results are unspecified. literally unspecified. nobody knows. chaos. πŸ’€

πŸ’… OPTIONS πŸ’…

the strings utility shall conform to the Base Definitions volume of POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines, except for the unspecified usage of -. (yes, that same weird - thing. we're all just living with it.)

the following options shall be supported:

  • -a β€” scan files in their entirety, the whole thing, no crumbs left behind. if -a is not specified, it is implementation-defined what portion of each file is scanned for strings β€” so like, your mileage may vary, lowkey.
  • -n number β€” specify the minimum string length, where the number argument is a positive decimal integer. the default shall be 4. (told you it'd come back 😌)
  • -t format β€” write each string preceded by its byte offset from the start of the file. the format shall be dependent on the single character used as the format option-argument:
    • d β€” the offset shall be written in decimal.
    • o β€” the offset shall be written in octal.
    • x β€” the offset shall be written in hexadecimal.

πŸ“ OPERANDS πŸ“

the following operand shall be supported:

  • file β€” a pathname of a regular file to be used as input. if no file operand is specified, the strings utility shall read from the standard input. so it's flexible, she contains multitudes. πŸ’–

🌈 STDIN 🌈

see the INPUT FILES section. (it's right below, bestie, we got you.)


🧚 INPUT FILES 🧚

the input files named by the utility arguments or the standard input shall be regular files of any format. any format!! no judgment here, we love all formats equally. 🫢


πŸ‘‘ ENVIRONMENT VARIABLES πŸ‘‘

the following environment variables shall affect the execution of strings:

  • LANG β€” provide a default value for the internationalization variables that are unset or null. (see the Base Definitions volume of POSIX.1‐2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)
  • LC_ALL β€” if set to a non-empty string value, override the values of all the other internationalization variables. she's the boss. the main character. periodt.
  • LC_CTYPE β€” determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments and input files) and to identify printable strings.
  • LC_MESSAGES β€” determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
  • NLSPATH β€” determine the location of message catalogs for the processing of LC_MESSAGES.

πŸ’œ ASYNCHRONOUS EVENTS πŸ’œ

default. that's it. that's the whole section. iconic minimalism. ✨


πŸ”₯ STDOUT πŸ”₯

strings found shall be written to the standard output, one per line. clean. organized. we love to see it.

when the -t option is not specified, the format of the output shall be:

"%s", <string>

with the -t o option, the format of the output shall be:

"%o %s", <byte offset>, <string>

with the -t x option, the format of the output shall be:

"%x %s", <byte offset>, <string>

with the -t d option, the format of the output shall be:

"%d %s", <byte offset>, <string>

πŸ’€ STDERR πŸ’€

the standard error shall be used only for diagnostic messages. that's it. don't put your vibes there. πŸ™ˆ


πŸŽ€ OUTPUT FILES πŸŽ€

none. nothing. empty. she simply does not write files. slay.


πŸ¦‹ EXTENDED DESCRIPTION πŸ¦‹

none. (another iconic minimalist moment, we stan a short section ✨)


⭐ EXIT STATUS ⭐

the following exit values shall be returned:

  • 0 β€” successful completion. πŸŽ‰
  • >0 β€” an error occurred. 😭

🌸 CONSEQUENCES OF ERRORS 🌸

default.

the following sections are informative.


🌟 APPLICATION USAGE 🌟

by default the data area (as opposed to the text, bss, or header areas) of a binary executable file is scanned. implementations document which areas are scanned. so like, the manual says it, and your implementation says it, and together we figure it out. teamwork. 🫢

some historical implementations do not require NUL or <newline> terminators for strings to permit those languages that do not use NUL as a string terminator to have their strings written. (letting the old-school languages have their moment πŸ’…)


πŸ“ EXAMPLES πŸ“

none. (ngl, would've loved one, but the manual said no. respect. πŸ™ˆ)


πŸ’… RATIONALE πŸ’…

okay this is the tea section, get comfortable. β˜•

apart from rationalizing the option syntax and slight difficulties with object and executable binary files, strings is specified to match historical practice closely. the -a and -n options were introduced to replace the non-conforming - and -number options. these options are no longer specified by POSIX.1‐2008 but may be present in some implementations. so like... legacy behavior, iykyk. πŸ‘‘

the -o option historically means different things on different implementations. some use it to mean offset in decimal, while others use it as offset in octal. instead of trying to decide which way would be least objectionable, the -t option was added. it was originally named -O to mean offset, but was changed to -t to be consistent with od. the lore!!! the character development!!! 😭

the ISO C standard function isprint() is restricted to a domain of unsigned char. this volume of POSIX.1‐2017 requires implementations to write strings as defined by the current locale. 🌍


🌈 FUTURE DIRECTIONS 🌈

none. the future is... unspecified. very on brand. ✨


πŸŽ€ SEE ALSO πŸŽ€

  • localedef
  • nm

the Base Definitions volume of POSIX.1‐2017, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines. 🫢


portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page bestie, every last flag and footnote, we read it together like the icons we are. πŸ’…βœ¨

this has been a presentation of IEEE/The Open Group, 2017, STRINGS(1P) β€” mwah, take care of yourselves, drink water, and go find some strings. πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from