I am trying to bulk rename many folders but for some reason my approach does not seem to work. I am trying to use the following script but it does nothing. I am new to programming so any suggestions are appreciated. These are the folder names that i have.
test.custom.tmp untitledfolder.custom.tmp wis.custom.tmp
I need them renamed to
test untitledfolder wis
I am using the following script but it does nothing.
while read line; do
newname=$(echo "$line" | cut -f 1 -d '_')
mv $line newname;
done < read
Here i created a file called read with all the foldernames that need renaming.
What is wrong with this script and also is there a better way to get this done? Thanks.
read
a file? What is thedone < read
reading from? Also, what operating system are you using? Different systems have different tools available. – terdon May 31 '22 at 14:30test untitled wis
ortest untitledfolder wis
. – schrodingerscatcuriosity May 31 '22 at 14:30my.custom.name1
andmy.custom.name2
? – Kusalananda May 31 '22 at 14:35echo
is a POSIX command, its behaviour is left mostly unspecified and in practice it's not portable.read
is also a POSIX command, but you're using it improperly here if the intent is to read a line from a file. – Stéphane Chazelas May 31 '22 at 15:17rename
from util-linux ormmv
or similar instead...but the perl rename is the best tool for this job. – cas Jun 01 '22 at 09:35