Automated Terminal Command Help

Is there a command that someone could help me with, that would automate me having to:

  1. Go into multiple different folders (probably around 100)
  2. Check and see if there are either 1(+) subfolders within that
  3. If there are, check and see if there are either 1(+) .m4a / .m4p / .m4v files in the folder / subfolder
  4. If there are 1(+) .m4a / .m4p files in the folder / subfolder, copy them to a completely new folder titled "Music" on my Desktop

That would be it..

Thank you very much all!

Running:

find <dir> -type f -name "*.mp4" 

will list all the .mp4 files in dir or any number of subdirectories of <dir>, <dir> can be a space delimited list of directories.

So running:

find <dir> -type f -name "*.mp4" | awk '{ print "cp "$1" ~/Music" }' > tempscript.sh
./tempscript.sh

Will create script to copy all *.mp4 files found under <dir> into a folder called Music under your home directory and the run that script.

HTH

instead of writing to a script file ?!

first, check the available files.

find <dir> -type f -name "*.mp4"

then, copy the files.

find <dir> -type f -name "*.mp4" -exec cp {} ~/Music/ \; 

If need be, get confirmation for each file.,

find <dir> -type f -name "*.mp4" -ok cp {} ~/Music/ \;
/usr/bin/find x E /path/to/folder regex '.*\.(m[4po][34agpv]|mpeg|aac|asf|wmv)' print 

See if that works, should find all sorts of media files, then add the copy line after it works, also if you have files that may have all caps extensions, use iregex instead.