I am working on something and need to solve the following. I am giving a analogous version of mine problem.
Say we have a music directory, in which there are 200 directories corresponding to different movies. In each movie directory there are some music files.
Now, say a file music.mp3 is in folder movie.mp3 . I want to make a shell script such that it renames the file to movie_music.mp3 and put it in some folder that I mention to it. Basically, all the files in the subdirectories are to be renamed and to be put in a new directory.
Any workaround for this?
This script receives two arguments: the source folder and the destination folder. It will move every file under any directory under the source directory to the new directory with the new filename:
Here is a sample:
Assuming the following directory tree:
The following one-liner will create 'mv' commands you can use:
EDIT:
If your directory structure contains only the relevant directories, you can expand use the following grep instead:
Notice it looks file anything with at least one directory and one file. If you have multiple inner directories, it won't be good enough.
Bash: