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.