If you want to apply the renaming recursively to all files within the directory hierarchy under your current working directory, you can use Bash's globstar
feature. You need to activate this first. Type the following:
shopt -s globstar
rename "s/\[|\]/_/g" **
In other words, you just to activate the globstar
feature, then you can run your command with two stars (**
) instead of only one (*
). This will match all files in the directory hierarchy under the current working directory, i.e., regardless of how deeply they are nested under the current working directory.
If you only want to rename all files under the current working directory without the risk of renaming matching directory names too, you can use find
instead:
find . -type f -execdir rename -- 's/\[|\]/_/g' {} +
This will match all files containing the characters [
or ]
anywhere in the directory structure under your current working directory, then run your renaming routine on the subdirectories containing any matching files.
*/*
instead:rename "s/\[|\]/_/g" */*
– Byte Commander♦ Aug 9 '17 at 23:29*
with*/*
there, as I did in my comment. Type that while you are in the parent directory of those inside which you want to rename the files. – Byte Commander♦ Aug 9 '17 at 23:34