finding and copying files in subfolders to a unique folder giving them their path names

Viewed 15

I need to do a bash script in order to copy all files which are in various subfolders and sub-subfolders of a main directory to a unique another folder while giving them a new name indicating their source.

source paths and files are like:

MainDir/SubFolderX/SubSubFolderXY/fileZ.dat
MainDir/UnknowName../AnotherUnknowName../AnyFile.anyExtension

... etc

destination folder with renamed files would be:

NewDir/SubFolderX_SubSubFolderXY_fileZ.dat
NewDir/UnknowName.._AnotherUnknowName.._AnyFile.anyExtension

etc

What I know is that there is only 2 levels but the names of the subfolders, the subsubfolders, the files and their extensions could be anything.

Can anyone please let me know how to do this ?

Thanks

0 Answers
Related