Using Wildcards with 'rename' Using Wildcards with 'rename' unix unix

Using Wildcards with 'rename'


You can try this first to see what commands would be executed

for f in *; do echo mv $f `echo $f | sed 's/2010.*.TW.//'` ; done

If it's what you expect, you can remove echo from the command to execute

for f in *; do mv $f `echo $f | sed 's/2010.*.TW.//'` ; done


rename does not allow wildcards in the from and to strings. When you run rename 2010.306.18.*.*.*.*. "" * it is actually your shell which first expands the wildcard and then passes the result of the expansion to rename, hence why it does not work.

Instead of using rename, use a loop as follows:

for file in *do  tmp="${file##2010*TW.}"   # remove the file prefix  mv "$file" "${tmp/../_}"  # replace dots with underscoredone