Craft By Zen

Image from Boston University showing Today I learned
Image from Boston University showing Today I learned

1 min read

šŸ”–TIL   šŸ”–programming

TIL Bulk Rename MacOS CLI

I have a bunch of files I want to rename using the rename utility.

If youā€™ve installed the rename utility on your Mac, you can use it to mass rename files in the terminal. The rename utility typically follows a specific syntax, and itā€™s quite powerful for renaming multiple files according to certain patterns or rules.

Hereā€™s a basic example of how you can use the rename utility:

rename 's/old_pattern/new_pattern/' files_to_rename

For my markdown files, I have the following

rename 's/-clearlabs//' *-clearlabs.md

When dealing with filenames that contain spaces, youā€™ll need to escape those spaces in your command. Hereā€™s how you can do it using the rename command:

rename 's/ Clear Labs//' *.md

This command will remove the substring ā€ Clear Labsā€ (including the space) from all .md files in the current directory.