Linux Batch Rename Commands

Published: 04 Aug 2015 Category: linux_study

1. Replace first letter of all files’ name with ‘q’:

for i in `ls`; do mv -f $i `echo $i | sed 's/^./q/'`; done

same with a bash script:

for file in `ls`
do
  newfile =`echo $i | sed 's/^./q/'`
 mv $file $newfile
done

2. Replace first 5 letters with ‘abcde’

for i in `ls`; do mv -f $i `echo $i | sed 's/^...../abcde/'`;

3. Replace last 5 letters with ‘abcde’

for i in `ls`; do mv -f $i `echo $i | sed 's/.....$/abcde/'`;

4. Add ‘abcde’ to the front

for i in `ls`; do mv -f $i `echo "abcde"$i`; done

5. Convert all lower case to upper case

for i in `ls`; do mv -f $i `echo $i | tr a-z A-Z`; done