How to rename with prefix/suffix?

前端 未结 9 1520
独厮守ぢ
独厮守ぢ 2020-11-27 10:52

How do I do mv original.filename new.original.filename without retyping the original filename?

I would imagine being able to do something like mv

9条回答
  •  醉酒成梦
    2020-11-27 11:25

    Bulk rename files bash script

    #!/bin/bash
    # USAGE: cd FILESDIRECTORY; RENAMERFILEPATH/MultipleFileRenamer.sh FILENAMEPREFIX INITNUMBER
    # USAGE EXAMPLE: cd PHOTOS; /home/Desktop/MultipleFileRenamer.sh 2016_
    # VERSION: 2016.03.05.
    # COPYRIGHT: Harkály Gergő | mangoRDI (https://wwww.mangordi.com/) 
    
    # check isset INITNUMBER argument, if not, set 1 | INITNUMBER is the first number after renaming
    if [ -z "$2" ]
        then i=1;
    else
        i=$2;
    fi
    
    # counts the files to set leading zeros before number | max 1000 files
    count=$(ls -l * | wc -l)
    if [ $count -lt 10 ]
        then zeros=1;
    else
        if [ $count -lt 100 ]
            then zeros=2;
        else
            zeros=3
        fi
    fi
    
    # rename script
    for file in *
    do
        mv $file $1_$(printf %0"$zeros"d.%s ${i%.*} ${file##*.})
        let i="$i+1"
    done
    

提交回复
热议问题