---
slug: "find-bitlocker-file-like-grep-r-in-python"
title: "Since BitLocker decryption key files are in UTF-16, they cannot be searched with grep -R, so use a script to search."
description: "Build a Chromium kiosk for web signage on an OrangePi Zero 2W — OS install, Wayland setup, and auto-start configuration."
url: "https://www.ytyng.com/en/blog/find-bitlocker-file-like-grep-r-in-python"
publish_date: "2023-05-14T03:09:02Z"
created: "2023-05-14T03:09:02Z"
updated: "2026-05-11T13:21:48.924Z"
categories: []
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20250705/22583bad7d814848842d7490db02c15c.png.webp?width=768"
has_video: true
has_music: true
video_urls: ["https://media.ytyng.net/ytyng-blog/282/featured-video-1.mp4", "https://media.ytyng.net/ytyng-blog/282/featured-video-2.mp4", "https://media.ytyng.net/ytyng-blog/282/featured-video-3.mp4"]
music_urls: ["https://media.ytyng.net/ytyng-blog/282/featured-music-282-3.mp3", "https://media.ytyng.net/ytyng-blog/282/featured-music-282-4.mp3"]
lang: "en"
---

# Since BitLocker decryption key files are in UTF-16, they cannot be searched with grep -R, so use a script to search.

When encrypting Windows storage with BitLocker, you can save the key file as a file.

If you have multiple files and want to search for files with matching content, running something like

```shell
grep -R 'AABBCC' .
```
won't work because the file encoding is UTF-16.

A technique to make it match is described in the following StackOverflow post:
https://stackoverflow.com/questions/3752913/grepping-binary-files-and-utf16

According to this post, it seems possible to achieve it with:

```shell
grep -Ra 'A.A.B.B.C.C.' .
```
However, I opted not to use this method and wrote a Python script instead. In Python, you can read the content by using `decode('utf16', errors='ignore')` to convert it to a string.

```python
import glob
import os

bitlocker_key_save_dir = '<my-mounted-bitlocker-key-save-dir>'

needle = 'AABBCC'


def main():
    # Retrieve all files, including those in subdirectories, under bitlocker_key_save_dir
    for file_path in glob.glob(
        f'{bitlocker_key_save_dir}/**/*', recursive=True
    ):
        # Skip if file_path is not a file
        if not os.path.isfile(file_path):
            continue
        print(f'\r{file_path}', end='', flush=True)
        # Print the content
        content_bytes = open(file_path, 'rb').read()
        content = content_bytes.decode('utf16', errors='ignore')
        if needle in content:
            print('\n')
            print(content)


if __name__ == '__main__':
    main()
```
