The scenario I currently have is, I have multiple folders and each folder has traffic type (like ftp.csv, http.csv etc) and metrics (cpu.csv and memory.csv). folder1>cpu.csv http.csvfolder2>cpu.csvftp.csvAs the metrics file is of same name across all folders , say, cpu.csv, I want to rename cpu.csv in the folder containing ftp.csv to cpu_ftp.csv and in the folder of http.csv, I want to move cpu.csv into cpu_http.csvI want to move like the followingfolder1>cpu_http.csv http.csvPlease help me in achieving in bash script ?
Rename a file in a folder based on presence of another file
shell script;find;rename
With bash:#!/bin/bashfor d in /folder[0-9]*do    type=   # traffic type (either `http` or `ftp`)    if [ -f $d/ftp.csv ]; then     # check if file `ftp.csv` exists within a folder        type=ftp    elif [ -f $d/http.csv ]; then  # check if file `http.csv` exists within a folder        type=http    fi    # if `traffic type` was set and file `cpu.csv` exists - rename the file    if [ ! -z $type ] && [ -f $d/cpu.csv ]; then        mv $d/cpu.csv $d/cpu_$type.csv    fi        done