1

I'm still relatively new to Linux, so take it easy on a noob, eh?

I have scripts set up to move media files to a specific directory based on its name. I used a wildcard to accomplish this, but I need to make it more specific so that it only moves exactly what I want.

Example: mv /home/user/Downloads/*Horror* /home/user/Downloads/transmission/completed/Series/AHS/

I need to know if it's possible to include multiple wildcards to a single move command. In the preceeding example, I want the script to move all of the American Horror Story episodes to the AHS directory. The script works, but if I download anything else with the word 'horror' in it, that file will be moved as well.

Is what I'm asking possible, or is there a different method all together that I should be using?

  • It's not clear what you want. Your command moves all files with "Horror" as part of the name and will not affect files with "horror", because Unix file names are case-sensitive. If you want to move both, then use *[hH]orror* or {*Horror*,*horror*} in the name part. – AFH Oct 26 '14 at 22:57
  • As @AFH said, isn't clear what you want. What's multiple wildcards? It may help to remember that mv never sees wildcards, the shell interprets them. What's the command line you want mv to see? Also, check up on extglob, it may help you. Here's a decent explanation of various globbing tools in bash. Wouldn't mv .../American\ Horror* ..../destdir do what you want? – Rich Homolka Oct 26 '14 at 23:11
  • Maybe bringing up the wildcard wasn't necessary. I want to be able to move the file based on 2 different words. Instead of only moving files with the name horror, I would like to be able to move anything with the words American AND Horror, not American OR Horror. Is this possible? – Brandon Hood Oct 26 '14 at 23:24
0

Try using a wild card like *American*Horror*. You can also have additional wildcards in the source path such as /usr/home/D*/*American*Horror*. Depending what is in your downloads directory a simple patter like *A*H* may match the desired files.

You may be able to use pattern matching such as *[aA]merican*[hH]orror*.

I generally either echo the command by prefixing it with echo, or use ls list files matching the pattern before running the actual command. This gives an opportunity to tune the pattern before committing to action.

| improve this answer | |

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.