Normally the shell command cat /dev/urandom | strings -n16 would produce a list of ASCII strings useful for picking passwords. However, after the latest upgrade to MacOS Catalina strings output garbage ala:


What gives?

1 Answer 1


It seems that the strings command now honours the locale settings in the environment, in particular


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

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .