I want to copy .wrk files from subfolders to onr WRK folder.

Example: I have one main folder (MIDI) and there is subfolders (named by numbers) 1 - 21 subfolders, which are under that main folder.

Each of those 21 subfolders has 2 - 5 subfolders. And those 2 - 5 subfolders may have 3 subfolders.

So, is it possible to copy (.wrk) files from all folders and subfolders to one (WRK) folder which is under main folder (MIDI)?


Use find:

cd /path/to/MIDI
find {1..21} -type f -name "*.wrk" -exec cp -i {} ./MIDI/WRK/ \;

it only search within 1 to 21 directories and all of their sub dirs for any files with ".wrk" suffix, then it moves all of them to "WRK".

using -i we make sure nothing will get over written,

  • @Jari You're welcome, you can accept the answer if you think it was helpful to you by clicking on the gray tick. – Ravexina Aug 2 '17 at 16:34
  • I done something wrong, because I get message in terminal: mv: cannot move ‘16/koe.wrk’ to ‘./MIDI/WRK’: No such file or directory – Jari Aug 2 '17 at 16:38
  • make sure ./MIDI/WRK dir exists from where you are running the command. – Ravexina Aug 2 '17 at 16:41
  • Here is the path were I tried to use command: computer@computer-desktop:~/Music/Midi_things/MIDI/WRK$ – Jari Aug 2 '17 at 16:48
  • You have to be in ~/Music/Midi_things to get the things works: cd ~/Music/Midi_things – Ravexina Aug 2 '17 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.