0

Let's assume that I have these files:

  • /1/tEst.mp4
  • /1/Test.mP4
  • /1/subdirectory/TEST2.mp4
  • /1/.20181106Test2.mp4

How can I copy all of these files into /2/Videos with a single command line?

All files that end with “mp4” and have “test” inside the name should be included. Case-insensitive, if possible.

I could use the file explorer to search for all files named “test” and filter by video, but is there any way to do it from the terminal?

  • 1
    @JeffSchaller Your answer has been accepted. – neverMind9 Nov 18 '18 at 19:13
2

This seems doable in bash:

set -o nocasematch dotglob globstar
cp /1/**/*test*.mp4 /2/Videos/
  • Are those set options shell specific? Not everyone uses bash. – Mioriin Nov 7 '18 at 3:41
  • As I led with, I assumed bash for this solution. I'm sure there's a clever zsh solution, though! – Jeff Schaller Nov 7 '18 at 3:42
1

Tested with below command and it worked fine

find /location_from_where_files_need_be_copied -type f -iname "Test*.mp4" -exec cp -t /targetlocation {} \; 
  • 3
    The question gave the starting location and destination; I think your answer would be more value/useful with those included. Also, I don't think "2" is a requirement for the filename - it says "ends with mp4 and contains test" – Jeff Schaller Nov 7 '18 at 3:40

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.