It seems that the strings
command now honours the locale settings in the environment, in particular
LC_CTYPE
This variable determines the locale category for character handling
functions, such as tolower(), toupper() and isalpha(). This
environment variable determines the interpretation of sequences of
bytes of text data as characters (for example, single- as opposed to
multi-byte characters), the classification of characters (for example,
alpha, digit, graph) and the behaviour of character classes.
Additional semantics of this variable, if any, are
implementation-dependent.
Setting LC_CTYPE
to C
restores the previous behaviour:
% cat /dev/urandom | LC_CTYPE=C strings -n 16
X! \*H=:e9c1`nzWk
$Hr/Q9q_b:BE-tS,[
/]59=+fPU"x-B9kk
:"*J9{5Q-tFpL=Xm$>
...
An alternative approach (taken from Shell Script /dev/urandom on Stack Overflow with minor modifications) is to filter out non-printable characters with the tr
tool and take the first 16 characters with dd
:
% cat /dev/urandom | LC_CTYPE=C tr -dc '[:print:]' | dd bs=16 count=1 2> /dev/null
This is much faster because it does not wait for 16 consecutive printable characters from the random source.