I have a set of files on a CentOS server that are in various sub-folders, and what I want to do is copy those files to a different server and sort them alphabetically by the folder they were in, and within that alphabetically by the file name.
The folders have names like First, Group01, Group02, Inbox, Last, and so I would want them sorted in that order.
What I need it to do is move and rename the files from:
/cd/cdart/11581/audio/files/Group01/msg0001.wav
/cd/cdart/11581/audio/files/Group01/msg0002.wav
/cd/cdart/11581/audio/files/Group02/msg0001.wav
to here
/cd/cdart/11581/audio/files/Group01_msg0001.wav
/cd/cdart/11581/audio/files/Group01_msg0002.wav
/cd/cdart/11581/audio/files/Group02_msg0001.wav etc
by pre-pending the directory name to the file so that the files are moved into a new directory.
I think it needs a nested loop to get the original files move them and rename them.
In BASH I am trying this :
find /home/123456/public_html/cd/cdart/11581/audio -maxdepth 1 -name “Group*” -type d | while read -r dir do
cp “{dir}/*"
"/home/123456/public_html/cd/cdart/11581/files/{dir##*/}.wav”
done
If you try this:
find /home/123456/public_html/cd/cdart/11581/audio -maxdepth 1 -name “Group*” -type d | while read -r dir do
cp “{dir}/msg0001.wav"
"/home/123456/public_html/cd/cdart/11581/files/{dir##*/}.wav”
done
It sort of works but it only pulls msg0001.wav from each of the
Group* folders… thus producing files
/cd/cdart/11581/audio/files/Group01.wav
/cd/cdart/11581/audio/files/Group02.wav
/cd/cdart/11581/audio/files/Group03.wav
etc.
which is not correct.
Any ideas on how to accomplish what I’d like to do? Thanks.