Skip to main content
100%

Rename md5 files (https://unix.stackexchange.com/questions/392129/rename-all-files-in-a-directory-to-the-md5-hash-of-their-filename-not-content)

✓ Published0🌍 Public
RRasinj
Last edited Nov 17, 2019
Created on Nov 17, 2019

This example demonstrates a shell one-liner that renames every file in the current directory to the MD5 hash of its filename while preserving the original file extension. The script iterates over each file with a `for` loop, computes the hash using `md5sum` on the filename with `echo -n` to avoid a trailing newline, and then prints the original and new names with `echo`. It uses parameter expansion to strip the hash’s trailing metadata and extract the extension via `${i##*.}`. The output shows the mapping without actually performing the rename, as the command only prints the `--` separated pair.

AI-generated description

Similar vizzes