rsync - копировать файлы, созданные старше x дней

I would not advise just collecting all files that match *.mp3 and then trimming the file names. You MAY want to run this same script AGAIN later (like next week) and it should NOT try to rename the same files a second time, making them even shorter and have naming conflicts.

Your example file names seem to be 001xyz1.mp3 and you want xyz.mp3

     KEEP_DIR=$PWD 
     cd /your/music/base_dir        # sub-dirs holding.mp3

     RCOUNT=0 ; SKIP=0 ; FCC=0


 for FFF in */001???1.mp3    
     do
     LOC="$(dirname $FFF)"   
     BAS="$(basename $FFF)"
     TRIM1="${BAS#1.mp3}"     #could use ${BAS:4:3}
     NEWF="$LOC/${TRIM1%001}.mp3"
     if [ -e "$NEWF" ] ; then
        echo "#-- File $NEWF already exists, not renaming $FFF"
        SKIP=$((SKIP+1))
     else
        mv $FFF $NEWF
        MCOUNT=$((MCOUNT+1))
     fi
     FCC=$((FCC+1))
 done

 echo "Renamed $MCOUNT mp3 files, of $FCC found. (Skipped $SKIP)"
 cd $KEEP_DIR

 #--[eof]
0
30.04.2020, 00:49
1 ответ

Вы запускали команду в каталоге /root. Путь добавляется к именам файлов, так как вы использовали .в качестве источника.

Измените .на /, и он должен работать с абсолютными путями к файлам, возвращаемыми find.

0
28.04.2021, 23:17

Теги

Похожие вопросы