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.
Written by Jeremy Wong and published on .