PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Mass Rename Files In Linux Using Bash

Go down

Mass Rename Files In Linux Using Bash Empty Mass Rename Files In Linux Using Bash

Post by jamied_uk 15th November 2019, 21:05






edit your .bashrc file

Code:
sudo gedit .bashrc

Code:
function rn() {
pathto="$(pwd)"
varin=$1
varout=$2
#
chrinlen=${#varin}
chroutlen=${#varout}
#
#
clear
echo "Changing Filetype (Mass Renamer) By J~Net 2019"
echo ""
echo "Char Length For Input $varin $chrinlen"
echo "Char Length For Input $varout $chroutlen"
echo ""
#
echo "Starting..."
for file in *.$varin ; do
  #
    mv $file $(echo $file | rev | cut -c5- | rev).$varout # this is for going from 3 char filetype to a 3
#    mv $file $(echo $file | rev | cut -c6- | rev).$varout # this is for going from 2 char filetype to a 3
done
echo "Finished!"
echo ""
ls
}

Code:
Example usage:
rn md txt
Then open a new terminal window and test!


Last edited by jamied_uk on 17th November 2019, 10:06; edited 3 times in total
jamied_uk
jamied_uk
Admin

Posts : 2943
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Mass Rename Files In Linux Using Bash Empty Re: Mass Rename Files In Linux Using Bash

Post by jamied_uk 17th November 2019, 07:06

You may need to some how detect the filetype char length and use case to make sure no twp dots end up in filename etc! good luck with that!
jamied_uk
jamied_uk
Admin

Posts : 2943
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum