I'm not sure if this has been asked here but here is my problem. I have files in lets say dir1 named:File 1.mp4File 2.mp4etc..Now on directory dir2, I have files named:Sub 1.srtSub 2.srtetc..How would I be able to rename Sub 1.srt so it becomes File 1.srt.  So basically renaming all *.srt files to have the name of *.mp4 files. There is the same amount of files on both directories and using printf %s\\n * files are sorted.
Rename files in directory based on names of files on another directory
linux;bash;files;rename
Since both directories contain the same number of files, here's an approach that saves file names in two arrays and then does the rename for each index in the list of array indices (as both arrays have the same length) :mp4paths=(dir1/*.mp4)              # save mp4 file names in arraymp4names=(${mp4paths[@]##*/})    # remove leading path componentsname=(${mp4names[@]%.*})         # remove extensionsrt=(dir2/*.srt)                   # save srt file names in arrayfor i in ${!srt[@]}              # for each index in the list of array indices do                                 # do stuff here...mv ${srt[$i]} dir2/${name[$i]}.srtdoneThis should work with all kind of file names.For a dry-run replace mv with printf '%s -> %s\n'.  