Friday, April 24, 2020

Shell tricks

Posting this for my own reference.

How to rename the full name of the files by replacing '/' (slash) with '_' (underscore) using zmv in zsh


$ zmv '(**/)(*.txt)' '${1//\//_}${2}'

The first pattern (**/) ensure that you go inside all subdirectories recursively,
the second pattern (*.txt) restricts this operation to only those files ending with ".txt".

${1//\//_} ensure that you replace every '/' in the first pattern to '_' .

No comments: