I’m running Centos 7. I need to have a cron job that moves everything from /media/tmp to /media/tv except the .grab and Transcode folders. Yesterday I thought that the following worked, but today it moves the Transcode folder as well.
mv -n /media/tmp/*!(Transcode)!(.grab) /media/tv/
I’ve found that the above does not work as a cron job as the ‘(‘ causes and error. I learned that I needed to escape those, but now I get
mv: cannot stat ‘/media/tmp/!(Transcode)!(.grab)’: No such file or directory
My current attempt at a bash script is
#!/bin/bash
mv -n '/media/tmp'/*!(Transcode)!(.grab) '/media/tv/'
My understanding is that the * is the problem, but using either ‘ or ” on the file path doesn’t seem to fix it like that post I found said it would.
Any ideas on how to get this to work correctly?
2
Answers
I’d just do it as something simple like (untested):
You’re trying to use extglob, which may not be enabled for cron. I would avoid that option entirely, iterating over the glob with a negative
!
regex match.