Is it possible to search for Base64 strings with grep? Say I have a list of text files and I want to find all the Base64 strings contained in them; is there any way to search for them? I mean I know they usually end with = or == and they also have sequences of bytes which relate to what letters they are encoded as within the base64 string. But as for searching for them in general (without knowing anything about what is encoded) I don't really know how to do so.

  • I think this is a duplicate for this one. Try the answer given on this request.
    – perko
    Sep 18, 2019 at 12:46
  • @perko I think it depends on the version of grep you're using. I was using git-bash for Windows and the answer in that duplicate didn't work.
    – leeand00
    Sep 18, 2019 at 13:04

1 Answer 1


You can look for strings which are composed only of valid Base64 characters, with the correct structure and padding if necessary:

grep -E '[A-Za-z0-9+/]{4}*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)'

This looks for any number of sequences of four Base64 characters, followed by either another four, or three with a single padding character, or two with two padding characters.

You must log in to answer this question.

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