[Bash] Batch Rename Every File in a Directory with zsh

Renaming every file in a directory with zsh is a common scenario when you're working with a series of related files. Using zsh's "for" loop, you can access the name of every file. Then using zsh's string replacement syntax of ${name/replace/with) you can adjust the file names.

for file in ./*
    mv $file ${file/-[string to remove]/[new string to add]}

 

If you just want to move string, for example, there is an extra "processed" string in the filename:

for file in ./*
    mv $file ${file/-processed/}

 

posted @ 2020-07-27 20:03  Zhentiw  阅读(108)  评论(0编辑  收藏  举报