FMeinicke's Wiki

Home

❯

Coding

❯

Calculate the MD5 hash of a file using a Python oneliner

Calculate the MD5 hash of a file using a Python oneliner

Nov 11, 20251 min read

  • hash/md5
  • python/hashlib/md5

md5 md5

Source

  • https://stackoverflow.com/a/16876405/
  • https://gist.github.com/FMeinicke/a312e3069a573428afcdec92eee76ee0
$ python -c "import sys, hashlib; from pathlib import Path; print(f'{sys.argv[1]}: {hashlib.md5(Path(sys.argv[1]).read_bytes()).hexdigest()}')" /path/to/file
b8bbb321fb1d6834e5335b74e7222d08

Graph View

Created with Quartz v4.5.0 © 2025

  • GitHub