How to copy and rename folders using bash? -
i have many folders similar names
sim00 sim01 sim02
and more. have file want copy of them named test.dat , copy them new folder named analysis , give them new name , such test_0.dat, test_1.dat , on.
here have tried far.
counter=0; value in "sim*/test.dat"; cp "$value" "analysis/${value%.dat}_$counter.dat ; ((counter++)); done
however, not work. can show me different solution?
the rule "quote variables" doesn't should quote wildcards, too. enclosing asterisk in double quotes prevents expansion.
you need remove path filename:
#! /bin/bash counter=0 file in sim*/test.dat; cp "$file" analysis/test_"$counter".dat ((counter++)) done
Comments
Post a Comment